package view.dlct.donvi.backing;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import java.sql.SQLException;
import java.sql.Timestamp;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import java.util.TimeZone;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;

import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.convert.DateTimeConverter;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.view.rich.component.rich.RichDialog;
import oracle.adf.view.rich.component.rich.RichPopup;
import oracle.adf.view.rich.component.rich.data.RichColumn;
import oracle.adf.view.rich.component.rich.data.RichTable;
import oracle.adf.view.rich.component.rich.input.RichInputDate;
import oracle.adf.view.rich.component.rich.input.RichInputFile;
import oracle.adf.view.rich.component.rich.input.RichInputText;
import oracle.adf.view.rich.component.rich.input.RichSelectOneChoice;
import oracle.adf.view.rich.component.rich.input.RichSelectOrderShuttle;
import oracle.adf.view.rich.component.rich.input.RichTextEditor;
import oracle.adf.view.rich.component.rich.layout.RichPanelFormLayout;
import oracle.adf.view.rich.component.rich.layout.RichPanelGroupLayout;
import oracle.adf.view.rich.component.rich.layout.RichPanelTabbed;
import oracle.adf.view.rich.component.rich.layout.RichShowDetailItem;
import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
import oracle.adf.view.rich.component.rich.nav.RichCommandLink;
import oracle.adf.view.rich.component.rich.nav.RichCommandToolbarButton;
import oracle.adf.view.rich.component.rich.output.RichOutputText;
import oracle.adf.view.rich.context.AdfFacesContext;
import oracle.adf.view.rich.event.DialogEvent;
import oracle.adf.view.rich.event.PopupCanceledEvent;

import oracle.jbo.Key;
import oracle.jbo.NameValuePairs;
import oracle.jbo.Row;
import oracle.jbo.RowSet;
import oracle.jbo.RowValException;
import oracle.jbo.SortCriteria;
import oracle.jbo.ViewObject;
import oracle.jbo.domain.BlobDomain;
import oracle.jbo.domain.ClobDomain;
import oracle.jbo.domain.DBSequence;
import oracle.jbo.domain.Number;

import org.apache.myfaces.trinidad.component.UIXInput;
import org.apache.myfaces.trinidad.event.SelectionEvent;
import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.RowKeySetImpl;
import org.apache.myfaces.trinidad.model.UploadedFile;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;
import org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding;

import view.common.Utils;
import view.common.search.AdvancedSearchGroup;
import view.common.search.AdvancedSearchItem;


public class DmDonViBean {
    private RichPanelFormLayout searchPanel = new RichPanelFormLayout();
    private RichTable tableDonVi = new RichTable();
    private RichSelectOneChoice goToPage = new RichSelectOneChoice();
    private RichPopup popupUpdate = new RichPopup();
    private RichDialog dialogUpdate = new RichDialog();
    private RichPopup popupDelete = new RichPopup();
    private RichSelectOrderShuttle selectLoaiDonVi =
        new RichSelectOrderShuttle();
    private RichSelectOrderShuttle selectNgonNgu =
        new RichSelectOrderShuttle();
    private RichPanelTabbed updatePanel = new RichPanelTabbed();
    private final String SEARCH_ID_PREFIX = "search";
    private final String UPDATE_ID_PREFIX = "update";
    private final String SEARCH_LOAI_DON_VI_ID = "searchloaidonviid";
    private final String SEARCH_TRANG_THAI_ID = "searchtrangthaiid";
    private final String TRANG_THAI = "trangthai";
    private final String ROW_KEY = "rowkey";
    private final String FILE_GROUP_ID_SUBFIX = "group";
    private final String FILE_DOWNLOAD_ID_SUBFIX = "download";
    private final String FILE_REMOVE_ID_SUBFIX = "remove";
    private final String DEFAULT_LANGCODE = "vi";
    private RichCommandToolbarButton firstPage =
        new RichCommandToolbarButton();
    private RichCommandToolbarButton prevPage = new RichCommandToolbarButton();
    private RichCommandToolbarButton nextPage = new RichCommandToolbarButton();
    private RichCommandToolbarButton lastPage = new RichCommandToolbarButton();
    private RichCommandButton fileDownloadButton;

    public DmDonViBean() {
    }

    public void beforePhase(PhaseEvent phaseEvent) {
        if (Boolean.FALSE.equals(Utils.getElExpression("#{adfFacesContext.postback}"))) {
            Utils.search("DlctDonViView1Iterator", new ArrayList());
            resetForm();
            getValue(0);
            rollback(null);
        }
    }

    private void resetForm() {
        searchPanel.getChildren().clear();
        tableDonVi.getChildren().clear();
        List<AdvancedSearchGroup> listASG = new ArrayList();
        AdvancedSearchGroup asg = new AdvancedSearchGroup();
        listASG.add(asg);
        AdvancedSearchItem asi = new AdvancedSearchItem();
        asg.getListChildren().add(asi);
        asi.setItemName("TrangThai");
        asi.setRequired(true);
        asi.getListValue().add(0,
                               new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        Utils.searchadvanced("DlctLoaiDonViView1Iterator", listASG);
        List<SelectItem> listSelectItem = new ArrayList();
        DCIteratorBinding loaiDonViView1Iterator =
            Utils.getIteratorBinding("DlctLoaiDonViView1Iterator");

        loaiDonViView1Iterator.setRangeSize(-1);
        Row[] rows = loaiDonViView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        RichSelectOneChoice selectSearchLoaiDonVi = new RichSelectOneChoice();
        for (int i = 0; i < rows.length; i++) {
            String id = ((DBSequence)rows[i].getAttribute("Id")).toString();
            String ten = (String)rows[i].getAttribute("Ten");
            SelectItem si = new SelectItem();
            si.setValue(id);
            si.setLabel(ten);
            listSelectItem.add(si);
        }
        UISelectItems uiSelectItems = new UISelectItems();
        uiSelectItems.setValue(listSelectItem);
        selectSearchLoaiDonVi.setId(SEARCH_LOAI_DON_VI_ID);
        selectSearchLoaiDonVi.setUnselectedLabel(Utils.getResourceBundle("CHON_LOAI_DON_VI"));
        selectSearchLoaiDonVi.setLabel(Utils.getResourceBundle("LOAI_DON_VI"));
        selectSearchLoaiDonVi.setValue(null);
        selectSearchLoaiDonVi.getChildren().clear();
        selectSearchLoaiDonVi.getChildren().add(uiSelectItems);
        selectSearchLoaiDonVi.setValuePassThru(true);
        selectSearchLoaiDonVi.setAutoSubmit(true);
        searchPanel.getChildren().add(selectSearchLoaiDonVi);
        listSelectItem = new ArrayList();
        for (Utils.ENUM_TRANG_THAI trangThai :
             Utils.ENUM_TRANG_THAI.values()) {
            SelectItem si = new SelectItem();
            si.setValue("" + trangThai.getId());
            si.setLabel(trangThai.getTen());
            listSelectItem.add(si);
        }
        uiSelectItems = new UISelectItems();
        uiSelectItems.setValue(listSelectItem);
        RichSelectOneChoice searchTrangThai = new RichSelectOneChoice();
        searchTrangThai.setId(SEARCH_TRANG_THAI_ID);
        searchTrangThai.setUnselectedLabel(Utils.getResourceBundle("CHON_TRANG_THAI"));
        searchTrangThai.setLabel(Utils.getResourceBundle("TRANG_THAI"));
        searchTrangThai.setValue(null);
        searchTrangThai.getChildren().clear();
        searchTrangThai.getChildren().add(uiSelectItems);
        searchTrangThai.setValuePassThru(true);
        searchTrangThai.setAutoSubmit(true);
        searchPanel.getChildren().add(searchTrangThai);

        listASG = new ArrayList();
        asg = new AdvancedSearchGroup();
        listASG.add(asg);
        asi = new AdvancedSearchItem();
        asg.getListChildren().add(asi);
        asi.setItemName("DlctLoaiTruongTt");
        asi.setRequired(true);
        asi.getListValue().add(0,
                               new Number(Utils.ENUM_LOAI_TRUONG_TT.DON_VI.getId()));
        asi = new AdvancedSearchItem();
        asg.getListChildren().add(asi);
        asi.setItemName("TrangThai");
        asi.setRequired(true);
        asi.getListValue().add(0,
                               new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        Utils.searchadvanced("DlctTruongTtView1Iterator", listASG);
        DCIteratorBinding truongTtView1Iterator =
            Utils.getIteratorBinding("DlctTruongTtView1Iterator");
        truongTtView1Iterator.setRangeSize(-1);
        rows = truongTtView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        for (int i = 0; i < rows.length; i++) {
            String id = ((DBSequence)rows[i].getAttribute("Id")).toString();
            String ten = (String)rows[i].getAttribute("TenTruong");
            Number kieuDuLieu = (Number)rows[i].getAttribute("KieuDuLieu");
            Number viTriHienThi = (Number)rows[i].getAttribute("ViTriHienThi");
            Number truongTtTu =
                (Number)rows[i].getAttribute("DlctTruongTtTuId");
            if (viTriHienThi != null && kieuDuLieu != null &&
                truongTtTu == null) {
                int viTri = viTriHienThi.intValue();
                int kieu = kieuDuLieu.intValue();
                if ((Utils.ENUM_VI_TRI_HIEN_THI.SEARCH.getId() & viTri) ==
                    Utils.ENUM_VI_TRI_HIEN_THI.SEARCH.getId()) {
                    List<UIComponent> components =
                        createSearchComponent(SEARCH_ID_PREFIX +
                                              rows[i].getKey().toStringFormat(false),
                                              ten, kieu);
                    if (components != null) {
                        searchPanel.getChildren().addAll(components);
                    }
                }
                if ((Utils.ENUM_VI_TRI_HIEN_THI.TABLE.getId() & viTri) ==
                    Utils.ENUM_VI_TRI_HIEN_THI.TABLE.getId()) {
                    UIComponent component = createColumn(id, ten, kieu);
                    if (component != null) {
                        tableDonVi.getChildren().add(component);
                    }
                }
            }
        }
        if (searchPanel.getChildren().size() > 0) {
            FacesContext fc = FacesContext.getCurrentInstance();
            Application app = fc.getApplication();
            ExpressionFactory elFactory = app.getExpressionFactory();
            ELContext elContext = fc.getELContext();
            MethodExpression methodExpression =
                elFactory.createMethodExpression(elContext,
                                                 "#{dmDonViBean.timKiem}",
                                                 null,
                                                 new Class[] { ActionEvent.class });
            ValueExpression valueExp =
                elFactory.createValueExpression(elContext,
                                                "#{adfBundle['view.ViewControllerBundle'].TIM_KIEM}",
                                                Object.class);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            RichCommandButton buttonSearch = new RichCommandButton();
            buttonSearch.setId("searchButton");
            buttonSearch.setInlineStyle("margin-bottom:10px;");
            buttonSearch.setValueExpression("text", valueExp);
            buttonSearch.getAttributes().put("actionListener",
                                             methodExpressionMethodBinding);
            searchPanel.getChildren().add(buttonSearch);
        }
        if (tableDonVi.getChildren().size() > 0) {
            FacesContext fc = FacesContext.getCurrentInstance();
            Application app = fc.getApplication();
            ExpressionFactory elFactory = app.getExpressionFactory();
            ELContext elContext = fc.getELContext();

            RichColumn column = new RichColumn();
            RichOutputText outputTexttrangThai = new RichOutputText();
            String str = "#{";
            for (Utils.ENUM_TRANG_THAI trangThai :
                 Utils.ENUM_TRANG_THAI.values()) {
                str =
str + "row['" + TRANG_THAI + "'] == " + trangThai.getId() + " ? '" +
  trangThai.getTen() + "' : ";
            }
            str = str + "'' }";
            ValueExpression valueExp =
                elFactory.createValueExpression(elContext, str, Object.class);
            outputTexttrangThai.setValueExpression("value", valueExp);
            column.getChildren().add(outputTexttrangThai);
            tableDonVi.getChildren().add(column);
            MethodExpression methodExpression =
                elFactory.createMethodExpression(elContext,
                                                 "#{dmDonViBean.navigation}",
                                                 null,
                                                 new Class[] { ActionEvent.class });
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            valueExp =
                    elFactory.createValueExpression(elContext, "#{adfBundle['view.ViewControllerBundle'].BAO_CAO}",
                                                    Object.class);
            column = new RichColumn();
            RichPanelGroupLayout groupLayout = new RichPanelGroupLayout();
            groupLayout.setLayout(RichPanelGroupLayout.LAYOUT_HORIZONTAL);
            RichCommandToolbarButton button = new RichCommandToolbarButton();
            button.setValueExpression("text", valueExp);
            valueExp =
                    elFactory.createValueExpression(elContext, "#{row['" + ROW_KEY +
                                                    "']}", Object.class);
            button.setValueExpression("rowKey", valueExp);
            button.getAttributes().put("fromAction", "Dsct");
            button.getAttributes().put("outcome", "adfMenu_Baocao");
            button.getAttributes().put("actionListener",
                                       methodExpressionMethodBinding);
            groupLayout.getChildren().add(button);
            valueExp =
                    elFactory.createValueExpression(elContext, "#{adfBundle['view.ViewControllerBundle'].CONG_BO_THONG_TIN}",
                                                    Object.class);
            button = new RichCommandToolbarButton();
            button.setValueExpression("text", valueExp);
            button.getAttributes().put("actionListener",
                                       methodExpressionMethodBinding);
            valueExp =
                    elFactory.createValueExpression(elContext, "#{row['" + ROW_KEY +
                                                    "']}", Object.class);
            button.setValueExpression("rowKey", valueExp);
            button.getAttributes().put("fromAction", "Dsct");
            button.getAttributes().put("outcome", "adfMenu_Cbtt");
            button.getAttributes().put("actionListener",
                                       methodExpressionMethodBinding);
            groupLayout.getChildren().add(button);
            valueExp =
                    elFactory.createValueExpression(elContext, "#{adfBundle['view.ViewControllerBundle'].KIEM_TOAN_VIEN}",
                                                    Object.class);
            button = new RichCommandToolbarButton();
            button.setValueExpression("text", valueExp);
            button.getAttributes().put("actionListener",
                                       methodExpressionMethodBinding);
            valueExp =
                    elFactory.createValueExpression(elContext, "#{row['" + ROW_KEY +
                                                    "']}", Object.class);
            button.setValueExpression("rowKey", valueExp);
            button.getAttributes().put("fromAction", "Dsct");
            button.getAttributes().put("outcome", "adfMenu_DonviKiemtoanvien");
            button.getAttributes().put("actionListener",
                                       methodExpressionMethodBinding);
            groupLayout.getChildren().add(button);
            column.getChildren().add(groupLayout);
            column.setWidth("250");
            tableDonVi.getChildren().add(column);
        }
    }

    private void getValue(int pageNum) {
        resetPaging("DlctDonViView1Iterator", pageNum);
        DCIteratorBinding donViView1Iterator =
            Utils.getIteratorBinding("DlctDonViView1Iterator");
        List<HashMap<String, Object>> listValue = new ArrayList();
        Row[] rows = donViView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        if (rows != null) {
            String currentRowKey = "";
            if (donViView1Iterator.getCurrentRow() != null &&
                donViView1Iterator.getCurrentRowIndexInRange() >= 0 &&
                donViView1Iterator.getCurrentRowIndexInRange() <
                donViView1Iterator.getRangeSize()) {
                currentRowKey =
                        donViView1Iterator.getCurrentRow().getKey().toStringFormat(false);
            }
            RowKeySet rowKeySet = tableDonVi.getSelectedRowKeys();
            if (rowKeySet == null) {
                rowKeySet = new RowKeySetImpl();
                tableDonVi.setSelectedRowKeys(rowKeySet);
            }
            rowKeySet.removeAll();
            for (int i = 0; i < rows.length; i++) {
                donViView1Iterator.setCurrentRowIndexInRange(i);
                String rowKey =
                    donViView1Iterator.getCurrentRow().getKey().toStringFormat(false);
                if (currentRowKey == null || currentRowKey.isEmpty()) {
                    currentRowKey = rowKey;
                }
                if (currentRowKey.equals(rowKey)) {
                    rowKeySet.add(i);
                }
                HashMap<String, Object> mapValue = new HashMap();
                mapValue.put(ROW_KEY, rowKey);
                mapValue.put(TRANG_THAI,
                             "" + donViView1Iterator.getCurrentRow().getAttribute("TrangThai"));
                DCIteratorBinding gtDvTtView1Iterator =
                    Utils.getIteratorBinding("DlctGtDvTtView1Iterator");
                gtDvTtView1Iterator.setRangeSize(-1);
                Row[] rowsGtTt = gtDvTtView1Iterator.getAllRowsInRange();
                if (rowsGtTt == null) {
                    rowsGtTt = new Row[] { };
                }
                for (int j = 0; j < rowsGtTt.length; j++) {
                    Row truongTtRow =
                        (Row)rowsGtTt[j].getAttribute("DlctTruongTtView");
                    if (truongTtRow != null) {
                        Number id =
                            ((DBSequence)truongTtRow.getAttribute("Id")).getSequenceNumber();
                        Number kieuDuLieu =
                            (Number)truongTtRow.getAttribute("KieuDuLieu");
                        Number truongTtTu =
                            (Number)truongTtRow.getAttribute("DlctTruongTtTuId");
                        if (id != null && kieuDuLieu != null &&
                            truongTtTu == null) {
                            int kieu = kieuDuLieu.intValue();
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                Number valNumber =
                                    (Number)rowsGtTt[j].getAttribute("ValNumber");
                                if (valNumber != null) {
                                    mapValue.put(id.toString(),
                                                 valNumber.toString());
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                String valVarchar =
                                    (String)rowsGtTt[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    mapValue.put(id.toString(), valVarchar);
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                String valVarchar =
                                    (String)rowsGtTt[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    mapValue.put(id.toString(), valVarchar);
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                String valVarchar =
                                    (String)rowsGtTt[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    mapValue.put(id.toString(), valVarchar);
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                oracle.jbo.domain.Date valDate =
                                    (oracle.jbo.domain.Date)rowsGtTt[j].getAttribute("ValDate");
                                if (valDate != null) {
                                    java.util.Date date = valDate.dateValue();
                                    if (date != null) {
                                        mapValue.put(id.toString(), date);
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                ClobDomain valClob =
                                    (ClobDomain)rowsGtTt[j].getAttribute("ValClob");
                                if (valClob != null) {
                                    mapValue.put(id.toString(),
                                                 valClob.toString());
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                Row fileViewRow =
                                    (Row)rowsGtTt[j].getAttribute("HtFileView");
                                if (fileViewRow != null) {
                                    String tenFile =
                                        (String)fileViewRow.getAttribute("TenFile");
                                    if (tenFile != null) {
                                        mapValue.put(id.toString(), tenFile);
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
                                Row fileViewRow =
                                    (Row)rowsGtTt[j].getAttribute("HtFileView");
                                if (fileViewRow != null) {
                                    String tenFile =
                                        (String)fileViewRow.getAttribute("TenFile");
                                    if (tenFile != null) {
                                        mapValue.put(id.toString(), tenFile);
                                    }
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId()) {
                                Row loaiChungKhoanRow =
                                    (Row)rowsGtTt[j].getAttribute("DlctLoaiChungKhoanView");
                                if (loaiChungKhoanRow != null) {
                                    RowSet gtLckTtRowSet =
                                        (RowSet)loaiChungKhoanRow.getAttribute("DlctGtLckTtView");
                                    String ten = "";
                                    if (gtLckTtRowSet != null) {
                                        gtLckTtRowSet.setRangeSize(-1);
                                        Row[] gtLckTtRows =
                                            gtLckTtRowSet.getAllRowsInRange();
                                        if (gtLckTtRows == null) {
                                            gtLckTtRows = new Row[] { };
                                        }
                                        for (int k = 0; k < gtLckTtRows.length;
                                             k++) {
                                            Row gtLckTtTruongTtRow =
                                                (Row)gtLckTtRows[k].getAttribute("DlctTruongTtView");
                                            Number gtLckTtKieuDuLieu =
                                                (Number)gtLckTtTruongTtRow.getAttribute("KieuDuLieu");
                                            Number gtLckTtViTriHienThi =
                                                (Number)gtLckTtTruongTtRow.getAttribute("ViTriHienThi");
                                            Number lckTruongTtTu =
                                                (Number)gtLckTtTruongTtRow.getAttribute("DlctTruongTtTuId");
                                            if (gtLckTtViTriHienThi != null &&
                                                gtLckTtKieuDuLieu != null &&
                                                lckTruongTtTu == null) {
                                                int gtLckviTri =
                                                    gtLckTtViTriHienThi.intValue();
                                                int gtLckKieu =
                                                    gtLckTtKieuDuLieu.intValue();
                                                if ((Utils.ENUM_VI_TRI_HIEN_THI.SELECT.getId() &
                                                     gtLckviTri) ==
                                                    Utils.ENUM_VI_TRI_HIEN_THI.SELECT.getId()) {
                                                    if (gtLckKieu ==
                                                        Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                                        Number valNumber =
                                                            (Number)gtLckTtRows[k].getAttribute("ValNumber");
                                                        if (valNumber !=
                                                            null) {
                                                            ten =
ten + valNumber.toString() + " ";
                                                        }
                                                    }
                                                    if (gtLckKieu ==
                                                        Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                                        String valVarchar =
                                                            (String)gtLckTtRows[k].getAttribute("ValVarchar");
                                                        if (valVarchar !=
                                                            null) {
                                                            ten =
ten + valVarchar + " ";
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    mapValue.put(id.toString(), ten);
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
                                Row sanGiaoDichRow =
                                    (Row)rowsGtTt[j].getAttribute("DlctSanGiaoDichView");
                                if (sanGiaoDichRow != null) {
                                    RowSet gtSgdTtRowSet =
                                        (RowSet)sanGiaoDichRow.getAttribute("DlctGtSgdTtView");
                                    String ten = "";
                                    if (gtSgdTtRowSet != null) {
                                        gtSgdTtRowSet.setRangeSize(-1);
                                        Row[] gtSgdTtRows =
                                            gtSgdTtRowSet.getAllRowsInRange();
                                        if (gtSgdTtRows == null) {
                                            gtSgdTtRows = new Row[] { };
                                        }
                                        for (int k = 0; k < gtSgdTtRows.length;
                                             k++) {
                                            Row gtSgdTtTruongTtRow =
                                                (Row)gtSgdTtRows[k].getAttribute("DlctTruongTtView");
                                            Number gtSgdTtKieuDuLieu =
                                                (Number)gtSgdTtTruongTtRow.getAttribute("KieuDuLieu");
                                            Number gtSgdTtViTriHienThi =
                                                (Number)gtSgdTtTruongTtRow.getAttribute("ViTriHienThi");
                                            Number lckTruongTtTu =
                                                (Number)gtSgdTtTruongTtRow.getAttribute("DlctTruongTtTuId");
                                            if (gtSgdTtViTriHienThi != null &&
                                                gtSgdTtKieuDuLieu != null &&
                                                lckTruongTtTu == null) {
                                                int gtLckviTri =
                                                    gtSgdTtViTriHienThi.intValue();
                                                int gtLckKieu =
                                                    gtSgdTtKieuDuLieu.intValue();
                                                if ((Utils.ENUM_VI_TRI_HIEN_THI.SELECT.getId() &
                                                     gtLckviTri) ==
                                                    Utils.ENUM_VI_TRI_HIEN_THI.SELECT.getId()) {
                                                    if (gtLckKieu ==
                                                        Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                                        Number valNumber =
                                                            (Number)gtSgdTtRows[k].getAttribute("ValNumber");
                                                        if (valNumber !=
                                                            null) {
                                                            ten =
ten + valNumber.toString() + " ";
                                                        }
                                                    }
                                                    if (gtLckKieu ==
                                                        Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                                        String valVarchar =
                                                            (String)gtSgdTtRows[k].getAttribute("ValVarchar");
                                                        if (valVarchar !=
                                                            null) {
                                                            ten =
ten + valVarchar + " ";
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    mapValue.put(id.toString(), ten);
                                }
                            }
                        }
                    }
                }
                listValue.add(mapValue);
            }
            if (currentRowKey != null && currentRowKey.isEmpty() == false) {
                donViView1Iterator.setCurrentRowWithKey(currentRowKey);
            }
        }
        tableDonVi.setValue(listValue);
    }

    private void resetPaging(String iteratorName, int pageNum) {
        DCIteratorBinding iterator = Utils.getIteratorBinding(iteratorName);
        int rowCount = (int)iterator.getEstimatedRowCount();
        int pageSize = Utils.getPageSize("HtCauHinhView1Iterator");
        int pageCount = 1;
        if (rowCount > pageSize) {
            if (rowCount % pageSize == 0) {
                pageCount = rowCount / pageSize;
            } else {
                pageCount = rowCount / pageSize + 1;
            }
        }

        if (pageNum < 1) {
            pageNum = 1;
        }
        if (pageNum > pageCount) {
            pageNum = pageCount;
        }
        if (pageNum == 1) {
            firstPage.setDisabled(true);
            prevPage.setDisabled(true);
        } else {
            firstPage.setDisabled(false);
            prevPage.setDisabled(false);
        }
        if (pageNum == pageCount) {
            lastPage.setDisabled(true);
            nextPage.setDisabled(true);
        } else {
            lastPage.setDisabled(false);
            nextPage.setDisabled(false);
        }
        int first = 1;
        if (pageNum < 5) {
            first = 1;
        } else if (pageNum + 9 > pageCount) {
            if (pageNum + 4 > pageCount) {
                if (pageCount - 6 < 1)
                    first = 1;
                else {
                    first = pageCount - 6;
                }
            } else {
                if (pageCount < 10) {
                    first = 1;
                } else {
                    first = pageNum - 4;
                }
            }
        } else {
            first = pageNum - 4;
        }

        List<SelectItem> listSelectItem = new ArrayList();

        for (int i = first, j = 0; i <= pageCount && j < 10; i++, j++) {
            SelectItem si = new SelectItem();
            si.setValue("" + i);
            si.setLabel(String.valueOf(i));
            listSelectItem.add(si);
        }
        UISelectItems uiSelectItems = new UISelectItems();
        uiSelectItems.setValue(listSelectItem);
        goToPage.setValue("" + pageNum);
        goToPage.getChildren().clear();
        goToPage.getChildren().add(uiSelectItems);
        goToPage.setValuePassThru(true);
        goToPage.setAutoSubmit(true);
        Row currentRow = iterator.getCurrentRow();
        iterator.executeQuery();
        if (currentRow != null) {
            iterator.setCurrentRowWithKey(currentRow.getKey().toStringFormat(false));
        }
        if ((pageNum) * pageSize > rowCount) {
            iterator.setRangeSize(rowCount - (pageNum - 1) * pageSize);
        } else {
            iterator.setRangeSize(pageSize);
        }
        iterator.setRangeStart((pageNum - 1) * pageSize);

        AdfFacesContext.getCurrentInstance().addPartialTarget(firstPage);
        AdfFacesContext.getCurrentInstance().addPartialTarget(prevPage);
        AdfFacesContext.getCurrentInstance().addPartialTarget(nextPage);
        AdfFacesContext.getCurrentInstance().addPartialTarget(lastPage);
        AdfFacesContext.getCurrentInstance().addPartialTarget(goToPage);
    }

    public void makeCurrent(SelectionEvent selectionEvent) {
        Map<String, Object> mapSelectedRow =
            (Map<String, Object>)tableDonVi.getSelectedRowData();
        if (mapSelectedRow != null) {
            DCIteratorBinding donViView1Iterator =
                Utils.getIteratorBinding("DlctDonViView1Iterator");
            donViView1Iterator.setCurrentRowWithKey((String)mapSelectedRow.get(ROW_KEY));
        }
    }

    public void showPopupThemMoi(ActionEvent actionEvent) {
        Utils.search("DlctDonViView1Iterator", new ArrayList());
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();

        List<AdvancedSearchGroup> listASG = new ArrayList();
        AdvancedSearchGroup asg = new AdvancedSearchGroup();
        listASG.add(asg);
        AdvancedSearchItem asi = new AdvancedSearchItem();
        asg.getListChildren().add(asi);
        asi.setItemName("TrangThai");
        asi.setRequired(true);
        asi.getListValue().add(0,
                               new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        Utils.searchadvanced("DlctLoaiDonViView1Iterator", listASG);
        List<SelectItem> listSelectItem = new ArrayList();
        DCIteratorBinding loaiDonViView1Iterator =
            Utils.getIteratorBinding("DlctLoaiDonViView1Iterator");

        loaiDonViView1Iterator.setRangeSize(-1);
        Row[] rows = loaiDonViView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        for (int i = 0; i < rows.length; i++) {
            String id = ((DBSequence)rows[i].getAttribute("Id")).toString();
            String ten = (String)rows[i].getAttribute("Ten");
            SelectItem si = new SelectItem();
            si.setValue(id);
            si.setLabel(ten);
            listSelectItem.add(si);
        }
        UISelectItems uiSelectItems = new UISelectItems();
        uiSelectItems.setValue(listSelectItem);
        //selectLoaiDonVi.setLabel("loaidonvi");
        selectLoaiDonVi.setValue(null);
        selectLoaiDonVi.getChildren().clear();
        selectLoaiDonVi.getChildren().add(uiSelectItems);
        selectLoaiDonVi.setValuePassThru(true);
        selectLoaiDonVi.setAutoSubmit(true);
        MethodExpression methodExpression =
            elFactory.createMethodExpression(elContext,
                                             "#{dmDonViBean.changeLoaiDonVi}",
                                             null,
                                             new Class[] { ValueChangeEvent.class });
        MethodExpressionMethodBinding methodExpressionMethodBinding =
            new MethodExpressionMethodBinding(methodExpression);
        selectLoaiDonVi.getAttributes().put("valueChangeListener",
                                            methodExpressionMethodBinding);

        uiSelectItems = new UISelectItems();
        uiSelectItems.setValue(new ArrayList());
        //selectNgonNgu.setLabel("ngonngu");
        selectNgonNgu.setValue(null);
        selectNgonNgu.getChildren().clear();
        selectNgonNgu.getChildren().add(uiSelectItems);
        selectNgonNgu.setValuePassThru(true);
        selectNgonNgu.setAutoSubmit(true);
        methodExpression =
                elFactory.createMethodExpression(elContext, "#{dmDonViBean.changeNgonNgu}",
                                                 null,
                                                 new Class[] { ValueChangeEvent.class });
        methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
        selectNgonNgu.getAttributes().put("valueChangeListener",
                                          methodExpressionMethodBinding);
        updatePanel.getChildren().clear();
        updatePanel.setVisible(false);
        updatePanel.setChildCreation(RichPanelTabbed.CHILD_CREATION_LAZY_UNCACHED);
        dialogUpdate.setTitle((String)Utils.getElExpression("#{adfBundle['view.ViewControllerBundle'].THEM_MOI}"));
        dialogUpdate.setAffirmativeTextAndAccessKey((String)Utils.getElExpression("#{adfBundle['view.ViewControllerBundle'].THEM_MOI}"));


        DCIteratorBinding donViView1Iterator =
            Utils.getIteratorBinding("DlctDonViView1Iterator");
        Row row =
            donViView1Iterator.getViewObject().createAndInitRow(new NameValuePairs());
        donViView1Iterator.executeQuery();
        donViView1Iterator.setCurrentRowWithKey(row.getKey().toStringFormat(false));
        Utils.showPopup(popupUpdate);
    }

    public void showPopupSua(ActionEvent actionEvent) {
        if (tableDonVi.getSelectedRowData() != null) {
            DCIteratorBinding dvLdvView1Iterator =
                Utils.getIteratorBinding("DlctDvLdvView1Iterator");
            DCIteratorBinding dvNnView1Iterator =
                Utils.getIteratorBinding("DlctDvNnView1Iterator");
            DCIteratorBinding gtDvTtView1Iterator =
                Utils.getIteratorBinding("DlctGtDvTtView1Iterator");

            dvLdvView1Iterator.setRangeSize(-1);
            Row[] rows = dvLdvView1Iterator.getAllRowsInRange();
            if (rows == null) {
                rows = new Row[] { };
            }
            List<String> listLoaiDonViId = new ArrayList();
            for (int i = 0; i < rows.length; i++) {
                Number loaiDonViId =
                    (Number)rows[i].getAttribute("DlctLoaiDonViId");
                Row dlctLoaiDonViRow = (Row)rows[i].getAttribute("DlctLoaiDonViView");
                if(dlctLoaiDonViRow!=null){
                Number trangThai = (Number)dlctLoaiDonViRow.getAttribute("TrangThai");
                if (loaiDonViId != null&&trangThai!=null&&Utils.ENUM_TRANG_THAI.CONG_BO.getId()==trangThai.intValue()) {
                    listLoaiDonViId.add(loaiDonViId.toString());
                }
                }
            }
            dvNnView1Iterator.setRangeSize(-1);
            rows = dvNnView1Iterator.getAllRowsInRange();
            if (rows == null) {
                rows = new Row[] { };
            }
            List<String> listNgonNguId = new ArrayList();
            for (int i = 0; i < rows.length; i++) {
                Number ngonNguId = (Number)rows[i].getAttribute("DlctNgonNgu");
                if (ngonNguId != null) {
                    listNgonNguId.add(ngonNguId.toString());
                }
            }


            FacesContext fc = FacesContext.getCurrentInstance();
            Application app = fc.getApplication();
            ExpressionFactory elFactory = app.getExpressionFactory();
            ELContext elContext = fc.getELContext();


            List<AdvancedSearchGroup> listASG = new ArrayList();
            AdvancedSearchGroup asg = new AdvancedSearchGroup();
            listASG.add(asg);
            AdvancedSearchItem asi = new AdvancedSearchItem();
            asg.getListChildren().add(asi);
            asi.setItemName("TrangThai");
            asi.setRequired(true);
            asi.getListValue().add(0,
                                   new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
            Utils.searchadvanced("DlctLoaiDonViView1Iterator", listASG);
            List<SelectItem> listSelectItem = new ArrayList();
            DCIteratorBinding loaiDonViView1Iterator =
                Utils.getIteratorBinding("DlctLoaiDonViView1Iterator");

            loaiDonViView1Iterator.setRangeSize(-1);
            rows = loaiDonViView1Iterator.getAllRowsInRange();
            if (rows == null) {
                rows = new Row[] { };
            }
            for (int i = 0; i < rows.length; i++) {
                String id =
                    ((DBSequence)rows[i].getAttribute("Id")).toString();
                String ten = (String)rows[i].getAttribute("Ten");
                SelectItem si = new SelectItem();
                si.setValue(id);
                si.setLabel(ten);
                listSelectItem.add(si);
            }
            UISelectItems uiSelectItems = new UISelectItems();
            uiSelectItems.setValue(listSelectItem);
            //selectLoaiDonVi.setLabel("loaidonvi");
            selectLoaiDonVi.setValue(listLoaiDonViId);
            selectLoaiDonVi.getChildren().clear();
            selectLoaiDonVi.getChildren().add(uiSelectItems);
            selectLoaiDonVi.setValuePassThru(true);
            selectLoaiDonVi.setAutoSubmit(true);
            MethodExpression methodExpression =
                elFactory.createMethodExpression(elContext,
                                                 "#{dmDonViBean.changeLoaiDonVi}",
                                                 null,
                                                 new Class[] { ValueChangeEvent.class });
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            selectLoaiDonVi.getAttributes().put("valueChangeListener",
                                                methodExpressionMethodBinding);


            searchNgonNgu(listLoaiDonViId);


            DCIteratorBinding ngonNguView1Iterator =
                Utils.getIteratorBinding("DlctNgonNguView1Iterator");
            listSelectItem = new ArrayList();
            ngonNguView1Iterator.setRangeSize(-1);
            rows = ngonNguView1Iterator.getAllRowsInRange();
            if (rows == null) {
                rows = new Row[] { };
            }
            for (int i = 0; i < rows.length; i++) {
                String id =
                    ((DBSequence)rows[i].getAttribute("Id")).toString();
                String ma = (String)rows[i].getAttribute("Ma");
                String ten = (String)rows[i].getAttribute("Ten");
                SelectItem si = new SelectItem();
                si.setValue(id);
                si.setLabel(ma + "_" + ten);
                listSelectItem.add(si);
            }
            uiSelectItems = new UISelectItems();
            uiSelectItems.setValue(listSelectItem);
            //selectNgonNgu.setLabel("ngonngu");
            selectNgonNgu.setValue(listNgonNguId);
            selectNgonNgu.getChildren().clear();
            selectNgonNgu.getChildren().add(uiSelectItems);
            selectNgonNgu.setValuePassThru(true);
            selectNgonNgu.setAutoSubmit(true);
            methodExpression =
                    elFactory.createMethodExpression(elContext, "#{dmDonViBean.changeNgonNgu}",
                                                     null,
                                                     new Class[] { ValueChangeEvent.class });
            methodExpressionMethodBinding =
                    new MethodExpressionMethodBinding(methodExpression);
            selectNgonNgu.getAttributes().put("valueChangeListener",
                                              methodExpressionMethodBinding);
            updatePanel.getChildren().clear();
            updatePanel.setVisible(true);
            updatePanel.setChildCreation(RichPanelTabbed.CHILD_CREATION_LAZY_UNCACHED);

            Map<String, RichPanelFormLayout> mapNgonNguLayout = new HashMap();
            for (String ngonNguId : listNgonNguId) {
                ngonNguView1Iterator.setCurrentRowWithKeyValue(ngonNguId);
                RichShowDetailItem showDetailItem = new RichShowDetailItem();
                showDetailItem.setImmediate(true);
                showDetailItem.setText((String)ngonNguView1Iterator.getCurrentRow().getAttribute("Ten"));
                RichPanelFormLayout formLayout = new RichPanelFormLayout();
                mapNgonNguLayout.put(ngonNguId, formLayout);
                showDetailItem.getChildren().add(formLayout);
                updatePanel.getChildren().add(showDetailItem);
            }

            Map<Number, Object> mapValue = new HashMap();
            Map<Number, String> mapGtKey = new HashMap();
            gtDvTtView1Iterator.setRangeSize(-1);
            rows = gtDvTtView1Iterator.getAllRowsInRange();
            if (rows == null) {
                rows = new Row[] { };
            }
            for (int i = 0; i < rows.length; i++) {
                Row truongTtRow =
                    (Row)rows[i].getAttribute("DlctTruongTtView");
                if (truongTtRow != null) {
                    Number id =
                        ((DBSequence)truongTtRow.getAttribute("Id")).getSequenceNumber();
                    Number kieuDuLieu =
                        (Number)truongTtRow.getAttribute("KieuDuLieu");
                    Number truongTtTu =
                        (Number)truongTtRow.getAttribute("DlctTruongTtTuId");
                    if (id != null && kieuDuLieu != null &&
                        truongTtTu == null) {
                        int kieu = kieuDuLieu.intValue();
                        mapGtKey.put(id,
                                     rows[i].getKey().toStringFormat(false));
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                            Number valNumber =
                                (Number)rows[i].getAttribute("ValNumber");
                            if (valNumber != null) {
                                mapValue.put(id, valNumber.toString());
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                            String valVarchar =
                                (String)rows[i].getAttribute("ValVarchar");
                            if (valVarchar != null) {
                                mapValue.put(id, valVarchar);
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                            String valVarchar =
                                (String)rows[i].getAttribute("ValVarchar");
                            if (valVarchar != null) {
                                mapValue.put(id, valVarchar);
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                            String valVarchar =
                                (String)rows[i].getAttribute("ValVarchar");
                            if (valVarchar != null) {
                                mapValue.put(id, valVarchar);
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                            oracle.jbo.domain.Date valDate =
                                (oracle.jbo.domain.Date)rows[i].getAttribute("ValDate");
                            if (valDate != null) {
                                java.util.Date date = valDate.dateValue();
                                mapValue.put(id, date);
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                            ClobDomain valClob =
                                (ClobDomain)rows[i].getAttribute("ValClob");
                            if (valClob != null) {
                                mapValue.put(id, valClob.toString());
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                            Row fileViewRow =
                                (Row)rows[i].getAttribute("HtFileView");
                            if (fileViewRow != null) {
                                String tenFile =
                                    (String)fileViewRow.getAttribute("TenFile");
                                if (tenFile != null) {
                                    mapValue.put(id, tenFile);
                                }
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
                            Row fileViewRow =
                                (Row)rows[i].getAttribute("HtFileView");
                            if (fileViewRow != null) {
                                String tenFile =
                                    (String)fileViewRow.getAttribute("TenFile");
                                if (tenFile != null) {
                                    mapValue.put(id, tenFile);
                                }
                            }
                        }
                        if (kieu ==
                            Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId()) {
                            Number valNumber =
                                (Number)rows[i].getAttribute("DlctLoaiChungKhoanId");
                            if (valNumber != null) {
                                mapValue.put(id, valNumber.toString());
                            }
                        }
                        if (kieu ==
                            Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
                            Number valNumber =
                                (Number)rows[i].getAttribute("DlctSanGiaoDichId");
                            if (valNumber != null) {
                                mapValue.put(id, valNumber.toString());
                            }
                        }
                    }
                }
            }
            searchTruongTt(listLoaiDonViId);

            DCIteratorBinding truongTtView1Iterator =
                Utils.getIteratorBinding("DlctTruongTtView1Iterator");
            truongTtView1Iterator.setRangeSize(-1);
            rows = truongTtView1Iterator.getAllRowsInRange();
            if (rows == null) {
                rows = new Row[] { };
            }
            Map<String, Row> mapTruongTtRoot = new HashMap();
            for (int i = 0; i < rows.length; i++) {
                Row rowParent =
                    (Row)rows[i].getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                if (rowParent == null) {
                    String rowKey = rows[i].getKey().toStringFormat(false);
                    mapTruongTtRoot.put(rowKey, rows[i]);
                }
            }
            for (int i = 0; i < rows.length; i++) {
                Number id =
                    ((DBSequence)rows[i].getAttribute("Id")).getSequenceNumber();
                String ten = (String)rows[i].getAttribute("TenTruong");
                Number batBuoc = (Number)rows[i].getAttribute("BatBuoc");
                Number duyNhat = (Number)rows[i].getAttribute("DuyNhat");
                Number kieuDuLieu = (Number)rows[i].getAttribute("KieuDuLieu");
                Number ngonNguId =
                    (Number)rows[i].getAttribute("DlctNgonNguId");
                Row loopRow = rows[i];
                Row rootRow = null;
                while (loopRow != null) {
                    rootRow = loopRow;
                    loopRow =
                            (Row)loopRow.getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                }
                String rowKey = rows[i].getKey().toStringFormat(false);
                String rootKey = rootRow.getKey().toStringFormat(false);
                if (batBuoc != null && kieuDuLieu != null &&
                    ngonNguId != null) {
                    RichPanelFormLayout formLayout =
                        mapNgonNguLayout.get(String.valueOf(ngonNguId.intValue()));
                    if (rowKey.equals(rootKey) == false) {
                        Row checkRow = mapTruongTtRoot.get(rootKey);
                        if (checkRow == null) {
                            Number rootId =
                                ((DBSequence)rootRow.getAttribute("Id")).getSequenceNumber();
                            String gtKey = mapGtKey.get(rootId);
                            Object value = mapValue.get(rootId);
                            if (gtKey == null) {
                                NameValuePairs nvp = new NameValuePairs();
                                nvp.setAttribute("DlctTruongTtId", rootId);
                                nvp.setAttribute("DuyNhat", duyNhat);
                                Row row =
                                    gtDvTtView1Iterator.getViewObject().createAndInitRow(nvp);
                                gtKey = row.getKey().toStringFormat(false);
                                gtDvTtView1Iterator.executeQuery();
                            }
                            if (formLayout != null) {
                                List<UIComponent> components =
                                    createInputComponent(UPDATE_ID_PREFIX +
                                                         gtKey, ten, ngonNguId,
                                                         kieuDuLieu.intValue(),
                                                         batBuoc.intValue(),
                                                         value, false);
                                if (components != null) {
                                    formLayout.getChildren().addAll(components);
                                }
                            }
                            mapTruongTtRoot.put(rootKey, rows[i]);
                        } else {
                            Object value = checkRow.getAttribute("TenTruong");
                            if (formLayout != null) {
                                List<UIComponent> components =
                                    createInputComponent(null, ten, ngonNguId,
                                                         Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId(),
                                                         Utils.ENUM_BAT_BUOC.KHONG_BAT_BUOC.getId(),
                                                         value, true);
                                if (components != null) {
                                    formLayout.getChildren().addAll(components);
                                }
                            }
                        }
                    } else {
                        String gtKey = mapGtKey.get(id);
                        Object value = mapValue.get(id);
                        if (gtKey == null) {
                            NameValuePairs nvp = new NameValuePairs();
                            nvp.setAttribute("DlctTruongTtId", id);
                            nvp.setAttribute("DuyNhat", duyNhat);
                            Row row =
                                gtDvTtView1Iterator.getViewObject().createAndInitRow(nvp);
                            gtKey = row.getKey().toStringFormat(false);
                            gtDvTtView1Iterator.executeQuery();
                        }
                        if (formLayout != null) {
                            List<UIComponent> components =
                                createInputComponent(UPDATE_ID_PREFIX + gtKey,
                                                     ten, ngonNguId,
                                                     kieuDuLieu.intValue(),
                                                     batBuoc.intValue(), value,
                                                     false);
                            if (components != null) {
                                formLayout.getChildren().addAll(components);
                            }
                        }
                    }
                }
            }

            dialogUpdate.setTitle((String)Utils.getElExpression("#{adfBundle['view.ViewControllerBundle'].CAP_NHAT}"));
            dialogUpdate.setAffirmativeTextAndAccessKey((String)Utils.getElExpression("#{adfBundle['view.ViewControllerBundle'].CAP_NHAT}"));
            Utils.showPopup(popupUpdate);
        } else {
            String errorString =
                Utils.getResourceBundle("CHON_BAN_GHI_DE_THAO_TAC");
            FacesContext.getCurrentInstance().addMessage(null,
                                                         new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                          errorString,
                                                                          errorString));
        }
    }

    public void showPopupXoa(ActionEvent actionEvent) {
        if (tableDonVi.getSelectedRowData() != null) {
            Utils.showPopup(popupDelete);
        } else {
            String errorString =
                Utils.getResourceBundle("CHON_BAN_GHI_DE_THAO_TAC");
            FacesContext.getCurrentInstance().addMessage(null,
                                                         new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                          errorString,
                                                                          errorString));
        }
    }

    public void removeFile(ActionEvent actionEvent) {
        String rowKey = actionEvent.getComponent().getId();
        if (rowKey.startsWith(UPDATE_ID_PREFIX))
            rowKey = rowKey.substring(UPDATE_ID_PREFIX.length());
        if (rowKey.endsWith(FILE_REMOVE_ID_SUBFIX))
            rowKey =
                    rowKey.substring(0, rowKey.length() - FILE_REMOVE_ID_SUBFIX.length());
        UIComponent groupComponent =
            actionEvent.getComponent().findComponent(UPDATE_ID_PREFIX +
                                                     rowKey +
                                                     FILE_GROUP_ID_SUBFIX);
        if (groupComponent != null &&
            groupComponent instanceof RichPanelGroupLayout) {
            RichPanelGroupLayout groupLayout =
                (RichPanelGroupLayout)groupComponent;
            groupLayout.setVisible(false);
            AdfFacesContext.getCurrentInstance().addPartialTarget(groupLayout);
        }
        RichInputFile inputFile =
            (RichInputFile)actionEvent.getComponent().findComponent(UPDATE_ID_PREFIX +
                                                                    rowKey);
        inputFile.resetValue();
        DCIteratorBinding gtDvTtView1Iterator =
            Utils.getIteratorBinding("DlctGtDvTtView1Iterator");
        gtDvTtView1Iterator.setCurrentRowWithKey(rowKey);
        gtDvTtView1Iterator.getCurrentRow().setAttribute("ValNumber",
                                                         new Number(Utils.ENUM_TRANG_THAI.KHONG_CONG_BO.getId()));
    }

    public void navigation(ActionEvent actionEvent) {
        String rowKey =
            (String)actionEvent.getComponent().getAttributes().get("rowKey");
        String outcome =
            (String)actionEvent.getComponent().getAttributes().get("outcome");
        if (rowKey != null && outcome != null) {
            FacesContext fc = FacesContext.getCurrentInstance();
            DCIteratorBinding donViView1Iterator =
                Utils.getIteratorBinding("DlctDonViView1Iterator");
            donViView1Iterator.setCurrentRowWithKey(rowKey);
            fc.getApplication().getNavigationHandler().handleNavigation(fc, "",
                                                                        outcome);
        }
    }

    public void timKiem(ActionEvent actionEvent) {
        if (searchPanel.getChildren().size() > 0) {
            iteratorFilter();
            getValue(0);
            AdfFacesContext.getCurrentInstance().addPartialTarget(tableDonVi);
            AdfFacesContext.getCurrentInstance().partialUpdateNotify(tableDonVi);
        }
    }

    private void iteratorFilter() {
        {
            List<AdvancedSearchGroup> listASG = new ArrayList();
            AdvancedSearchGroup asg = new AdvancedSearchGroup();
            listASG.add(asg);
            AdvancedSearchItem asi = new AdvancedSearchItem();
            asg.getListChildren().add(asi);
            asi.setItemName("DlctLoaiTruongTt");
            asi.setRequired(true);
            asi.getListValue().add(0,
                                   new Number(Utils.ENUM_LOAI_TRUONG_TT.DON_VI.getId()));
            asi = new AdvancedSearchItem();
            asg.getListChildren().add(asi);
            asi.setItemName("TrangThai");
            asi.setRequired(true);
            asi.getListValue().add(0,
                                   new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
            Utils.searchadvanced("DlctTruongTtView1Iterator", listASG);
        }
        DCIteratorBinding truongTtView1Iterator =
            Utils.getIteratorBinding("DlctTruongTtView1Iterator");
        List<UIComponent> listUIComponent = new ArrayList();
        List<UIComponent> listDetailItem = new ArrayList();
        List<UIComponent> listDetailItemNext = new ArrayList();
        listDetailItemNext.add(searchPanel);
        while (listDetailItemNext.size() > 0) {
            listDetailItem = listDetailItemNext;
            listDetailItemNext = new ArrayList();
            for (UIComponent loopComponent : listDetailItem) {
                if (loopComponent != null) {
                    if (loopComponent instanceof RichPanelTabbed ||
                        loopComponent instanceof RichShowDetailItem ||
                        loopComponent instanceof RichPanelFormLayout) {
                        if (loopComponent.getChildCount() > 0) {
                            listDetailItemNext.addAll(loopComponent.getChildren());
                        }
                    }
                    if (loopComponent instanceof RichInputText ||
                        loopComponent instanceof RichInputDate ||
                        loopComponent instanceof RichSelectOneChoice) {
                        listUIComponent.add(loopComponent);
                    }
                }
            }
        }
        List<AdvancedSearchGroup> listASG = new ArrayList();
        for (UIComponent ui : listUIComponent) {
            if (ui.getId() != null &&
                SEARCH_LOAI_DON_VI_ID.equals(ui.getId())) {
                RichSelectOneChoice selectOneChoice = (RichSelectOneChoice)ui;
                Object valObject = selectOneChoice.getValue();
                if (valObject != null &&
                    valObject.toString().isEmpty() == false) {
                    try {
                        Number valNumber = new Number(valObject);
                        AdvancedSearchGroup asg = new AdvancedSearchGroup();
                        listASG.add(asg);
                        AdvancedSearchItem asi = new AdvancedSearchItem();
                        asg.getListChildren().add(asi);
                        asi.setItemName("DlctDvLdvView");
                        asi.setRequired(true);
                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                        AdvancedSearchGroup asgChild =
                            new AdvancedSearchGroup();
                        asi.getListChildren().add(asgChild);
                        AdvancedSearchItem asiChild = new AdvancedSearchItem();
                        asgChild.getListChildren().add(asiChild);
                        asiChild.setItemName("DlctLoaiDonViId");
                        asiChild.setRequired(true);
                        asiChild.getListValue().add(valNumber);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } else if (ui.getId() != null &&
                       SEARCH_TRANG_THAI_ID.equals(ui.getId())) {
                RichSelectOneChoice selectOneChoice = (RichSelectOneChoice)ui;
                Object valObject = selectOneChoice.getValue();
                if (valObject != null &&
                    valObject.toString().isEmpty() == false) {
                    try {
                        Number valNumber = new Number(valObject);
                        AdvancedSearchGroup asg = new AdvancedSearchGroup();
                        listASG.add(asg);
                        AdvancedSearchItem asi = new AdvancedSearchItem();
                        asg.getListChildren().add(asi);
                        asi.setItemName("TrangThai");
                        asi.setRequired(true);
                        asi.getListValue().add(valNumber);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } else if (ui.getId() != null) {
                String rowKey = ui.getId();
                if (rowKey.startsWith(SEARCH_ID_PREFIX))
                    rowKey = rowKey.substring(SEARCH_ID_PREFIX.length());
                truongTtView1Iterator.setCurrentRowWithKey(rowKey);
                Row truongTtRow = truongTtView1Iterator.getCurrentRow();
                if (truongTtRow != null) {
                    Row loopRow = truongTtRow;
                    Row rootRow = null;
                    while (loopRow != null) {
                        rootRow = loopRow;
                        loopRow =
                                (Row)loopRow.getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                    }
                    Number id =
                        ((DBSequence)rootRow.getAttribute("Id")).getSequenceNumber();
                    Number kieuDuLieu =
                        (Number)truongTtRow.getAttribute("KieuDuLieu");
                    Number truongTtTu =
                        (Number)truongTtRow.getAttribute("DlctTruongTtTuId");
                    if (kieuDuLieu != null && truongTtTu == null) {
                        int kieu = kieuDuLieu.intValue();
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                            RichInputText inputText = (RichInputText)ui;
                            Object valObject = inputText.getValue();
                            if (valObject != null &&
                                valObject.toString().isEmpty() == false) {
                                try {
                                    Number valNumber =
                                        new Number(valObject.toString().trim());
                                    AdvancedSearchGroup asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    AdvancedSearchItem asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("DlctGtDvTtView");
                                    asi.setRequired(true);
                                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    AdvancedSearchGroup asgChild =
                                        new AdvancedSearchGroup();
                                    asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                    asi.getListChildren().add(asgChild);
                                    AdvancedSearchItem asiChild =
                                        new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("DlctTruongTtId");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(id);
                                    asiChild = new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("ValNumber");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(valNumber);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    String errorString =
                                        Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                    FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                  errorString,
                                                                                                  errorString));
                                }
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                            RichInputText inputText = (RichInputText)ui;
                            Object valObject = inputText.getValue();
                            if (valObject != null &&
                                valObject.toString().isEmpty() == false) {
                                try {
                                    String valString =
                                        valObject.toString().trim();
                                    valString = valString.toUpperCase();
                                    AdvancedSearchGroup asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    AdvancedSearchItem asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("DlctGtDvTtView");
                                    asi.setRequired(true);
                                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    AdvancedSearchGroup asgChild =
                                        new AdvancedSearchGroup();
                                    asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                    asi.getListChildren().add(asgChild);
                                    AdvancedSearchItem asiChild =
                                        new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("DlctTruongTtId");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(id);
                                    asiChild = new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("ValVarchar");
                                    asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                    asiChild.setUpperColumns(true);
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(valString);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    String errorString =
                                        Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                    FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                  errorString,
                                                                                                  errorString));
                                }
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                            RichInputText inputText = (RichInputText)ui;
                            Object valObject = inputText.getValue();
                            if (valObject != null &&
                                valObject.toString().isEmpty() == false) {
                                try {
                                    String valString =
                                        valObject.toString().trim();
                                    valString = valString.toUpperCase();
                                    AdvancedSearchGroup asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    AdvancedSearchItem asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("DlctGtDvTtView");
                                    asi.setRequired(true);
                                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    AdvancedSearchGroup asgChild =
                                        new AdvancedSearchGroup();
                                    asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                    asi.getListChildren().add(asgChild);
                                    AdvancedSearchItem asiChild =
                                        new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("DlctTruongTtId");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(id);
                                    asiChild = new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("ValVarchar");
                                    asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                    asiChild.setUpperColumns(true);
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(valString);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    String errorString =
                                        Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                    FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                  errorString,
                                                                                                  errorString));
                                }
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                            RichInputText inputText = (RichInputText)ui;
                            Object valObject = inputText.getValue();
                            if (valObject != null &&
                                valObject.toString().isEmpty() == false) {
                                try {
                                    String valString =
                                        valObject.toString().trim();
                                    valString = valString.toUpperCase();
                                    AdvancedSearchGroup asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    AdvancedSearchItem asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("DlctGtDvTtView");
                                    asi.setRequired(true);
                                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    AdvancedSearchGroup asgChild =
                                        new AdvancedSearchGroup();
                                    asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                    asi.getListChildren().add(asgChild);
                                    AdvancedSearchItem asiChild =
                                        new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("DlctTruongTtId");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(id);
                                    asiChild = new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("ValVarchar");
                                    asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                    asiChild.setUpperColumns(true);
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(valString);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    String errorString =
                                        Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                    FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                  errorString,
                                                                                                  errorString));
                                }
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                            RichInputDate inputDate = (RichInputDate)ui;
                            Object valObject = inputDate.getValue();
                            if (valObject != null &&
                                valObject.toString().isEmpty() == false) {
                                try {
                                    java.util.Date javaDate =
                                        (java.util.Date)valObject;
                                    Timestamp timestamp =
                                        new Timestamp(javaDate.getTime());
                                    oracle.jbo.domain.Date valDate =
                                        new oracle.jbo.domain.Date(timestamp);
                                    AdvancedSearchGroup asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    AdvancedSearchItem asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("DlctGtDvTtView");
                                    asi.setRequired(true);
                                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    AdvancedSearchGroup asgChild =
                                        new AdvancedSearchGroup();
                                    asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                    asi.getListChildren().add(asgChild);
                                    AdvancedSearchItem asiChild =
                                        new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("DlctTruongTtId");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(id);
                                    asiChild = new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("ValDate");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(valDate);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    String errorString =
                                        Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                    FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                  errorString,
                                                                                                  errorString));
                                }
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                            RichInputText inputText = (RichInputText)ui;
                            Object valObject = inputText.getValue();
                            if (valObject != null &&
                                valObject.toString().isEmpty() == false) {
                                try {
                                    String valString = (String)valObject;
                                    valString = valString.toUpperCase();
                                    AdvancedSearchGroup asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    AdvancedSearchItem asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("DlctGtDvTtView");
                                    asi.setRequired(true);
                                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    AdvancedSearchGroup asgChild =
                                        new AdvancedSearchGroup();
                                    asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                    asi.getListChildren().add(asgChild);
                                    AdvancedSearchItem asiChild =
                                        new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("DlctTruongTtId");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(id);
                                    asiChild = new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("ValClob");
                                    asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                    asiChild.setUpperColumns(true);
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(valString);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    String errorString =
                                        Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                    FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                  errorString,
                                                                                                  errorString));
                                }
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                            RichInputText inputText = (RichInputText)ui;
                            Object valObject = inputText.getValue();
                            if (valObject != null &&
                                valObject.toString().isEmpty() == false) {
                                try {
                                    String valString = (String)valObject;
                                    valString = valString.toUpperCase();
                                    AdvancedSearchGroup asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    AdvancedSearchItem asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("DlctGtDvTtView");
                                    asi.setRequired(true);
                                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    AdvancedSearchGroup asgChild =
                                        new AdvancedSearchGroup();
                                    asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                    asi.getListChildren().add(asgChild);
                                    AdvancedSearchItem asiChild =
                                        new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("DlctTruongTtId");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(id);
                                    asiChild = new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("HtFileView");
                                    asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    asiChild.setRequired(true);

                                    AdvancedSearchGroup asgFile =
                                        new AdvancedSearchGroup();
                                    asiChild.getListChildren().add(asgFile);
                                    AdvancedSearchItem asiFile =
                                        new AdvancedSearchItem();
                                    asgFile.getListChildren().add(asiFile);
                                    asiFile.setItemName("TenFile");
                                    asiFile.setRequired(true);
                                    asiFile.getListValue().add(valString);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    String errorString =
                                        Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                    FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                  errorString,
                                                                                                  errorString));
                                }
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
                            RichInputText inputText = (RichInputText)ui;
                            Object valObject = inputText.getValue();
                            if (valObject != null &&
                                valObject.toString().isEmpty() == false) {
                                try {
                                    String valString = (String)valObject;
                                    valString = valString.toUpperCase();
                                    AdvancedSearchGroup asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    AdvancedSearchItem asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("DlctGtDvTtView");
                                    asi.setRequired(true);
                                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    AdvancedSearchGroup asgChild =
                                        new AdvancedSearchGroup();
                                    asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                    asi.getListChildren().add(asgChild);
                                    AdvancedSearchItem asiChild =
                                        new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("DlctTruongTtId");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(id);
                                    asiChild = new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("HtFileView");
                                    asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    asiChild.setRequired(true);

                                    AdvancedSearchGroup asgFile =
                                        new AdvancedSearchGroup();
                                    asiChild.getListChildren().add(asgFile);
                                    AdvancedSearchItem asiFile =
                                        new AdvancedSearchItem();
                                    asgFile.getListChildren().add(asiFile);
                                    asiFile.setItemName("TenFile");
                                    asiFile.setRequired(true);
                                    asiFile.getListValue().add(valString);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    String errorString =
                                        Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                    FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                  errorString,
                                                                                                  errorString));
                                }
                            }
                        }
                        if (kieu ==
                            Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId()) {
                            RichSelectOneChoice selectOneChoice =
                                (RichSelectOneChoice)ui;
                            Object valObject = selectOneChoice.getValue();
                            if (valObject != null &&
                                valObject.toString().isEmpty() == false) {
                                try {
                                    Number valNumber = new Number(valObject);
                                    AdvancedSearchGroup asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    AdvancedSearchItem asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("DlctGtDvTtView");
                                    asi.setRequired(true);
                                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    AdvancedSearchGroup asgChild =
                                        new AdvancedSearchGroup();
                                    asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                    asi.getListChildren().add(asgChild);
                                    AdvancedSearchItem asiChild =
                                        new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("DlctTruongTtId");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(id);
                                    asiChild = new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("DlctLoaiChungKhoanId");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(valNumber);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    String errorString =
                                        Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                    FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                  errorString,
                                                                                                  errorString));
                                }
                            }
                        }
                        if (kieu ==
                            Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
                            RichSelectOneChoice selectOneChoice =
                                (RichSelectOneChoice)ui;
                            Object valObject = selectOneChoice.getValue();
                            if (valObject != null &&
                                valObject.toString().isEmpty() == false) {
                                try {
                                    Number valNumber = new Number(valObject);
                                    AdvancedSearchGroup asg =
                                        new AdvancedSearchGroup();
                                    listASG.add(asg);
                                    AdvancedSearchItem asi =
                                        new AdvancedSearchItem();
                                    asg.getListChildren().add(asi);
                                    asi.setItemName("DlctGtDvTtView");
                                    asi.setRequired(true);
                                    asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                    AdvancedSearchGroup asgChild =
                                        new AdvancedSearchGroup();
                                    asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                    asi.getListChildren().add(asgChild);
                                    AdvancedSearchItem asiChild =
                                        new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("DlctTruongTtId");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(id);
                                    asiChild = new AdvancedSearchItem();
                                    asgChild.getListChildren().add(asiChild);
                                    asiChild.setItemName("DlctSanGiaoDichId");
                                    asiChild.setRequired(true);
                                    asiChild.getListValue().add(valNumber);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    String errorString =
                                        Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                    FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                  errorString,
                                                                                                  errorString));
                                }
                            }
                        }
                    }
                }
            }
        }
        Utils.searchadvanced("DlctDonViView1Iterator", listASG);
    }

    public void firstPage(ActionEvent actionEvent) {
        getValue(1);
    }

    public void prevPage(ActionEvent actionEvent) {
        Integer integer = null;
        try {
            integer = new Integer(goToPage.getValue().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (integer != null) {
            getValue(integer.intValue() - 1);
        }
    }

    public void nextPage(ActionEvent actionEvent) {
        Integer integer = null;
        try {
            integer = new Integer(goToPage.getValue().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (integer != null) {
            getValue(integer.intValue() + 1);
        }
    }

    public void lastPage(ActionEvent actionEvent) {
        getValue(999999);
    }

    public void changePage(ValueChangeEvent valueChangeEvent) {
        if (valueChangeEvent.getNewValue() != null) {
            if (valueChangeEvent.getOldValue() != null &&
                valueChangeEvent.getNewValue().toString().equals(valueChangeEvent.getOldValue().toString())) {
                return;
            }
            Integer integer = null;
            try {
                integer =
                        new Integer(valueChangeEvent.getNewValue().toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (integer != null) {
                getValue(integer.intValue());
            }
        }
    }

    public void changeUpdateField(ValueChangeEvent valueChangeEvent) {
        if (valueChangeEvent.getComponent().getId() != null) {
            String rowKey = valueChangeEvent.getComponent().getId();
            if (rowKey.startsWith(UPDATE_ID_PREFIX))
                rowKey = rowKey.substring(UPDATE_ID_PREFIX.length());
            DCIteratorBinding gtDvTtView1Iterator =
                Utils.getIteratorBinding("DlctGtDvTtView1Iterator");
            gtDvTtView1Iterator.setCurrentRowWithKey(rowKey);
            Row truongTtRow =
                (Row)gtDvTtView1Iterator.getCurrentRow().getAttribute("DlctTruongTtView");
            if (truongTtRow != null) {
                Number kieuDuLieu =
                    (Number)truongTtRow.getAttribute("KieuDuLieu");
                Number truongTtTu =
                    (Number)truongTtRow.getAttribute("DlctTruongTtTuId");
                if (kieuDuLieu != null && truongTtTu == null) {
                    int kieu = kieuDuLieu.intValue();
                    Object valObject = valueChangeEvent.getNewValue();
                    if (kieu == Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                        if (valObject != null &&
                            valObject.toString().isEmpty() == false) {
                            try {
                                Number valNumber =
                                    new Number(valObject.toString().trim());
                                gtDvTtView1Iterator.getCurrentRow().setAttribute("ValNumber",
                                                                                 valNumber);
                                try {
                                    gtDvTtView1Iterator.getCurrentRow().validate();
                                } catch (RowValException ex) {
                                    boolean duyNhat = false;
                                    Object[] objs = ex.getDetails();
                                    if (objs != null) {
                                        for (Object obj : objs) {
                                            if (obj instanceof
                                                RowValException) {
                                                RowValException e =
                                                    (RowValException)obj;
                                                Object[] detailObjs =
                                                    e.getErrorParameters();
                                                for (Object detailObj :
                                                     detailObjs) {
                                                    if (detailObj instanceof
                                                        String &&
                                                        "validateDuyNhat".equals(detailObj)) {
                                                        duyNhat = true;
                                                        String errorString =
                                                            Utils.getResourceBundle("GIA_TRI_KHONG_DUY_NHAT");
                                                        FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                                      errorString,
                                                                                                                      errorString));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (duyNhat == false) {
                                        throw ex;
                                    }
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                String errorString =
                                    Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                              errorString,
                                                                                              errorString));
                            }
                        } else {
                            gtDvTtView1Iterator.getCurrentRow().setAttribute("ValNumber",
                                                                             null);
                        }
                    }
                    if (kieu == Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                        if (valObject != null &&
                            valObject.toString().isEmpty() == false) {
                            try {
                                String valString = valObject.toString().trim();
                                gtDvTtView1Iterator.getCurrentRow().setAttribute("ValVarchar",
                                                                                 valString);
                                try {
                                    gtDvTtView1Iterator.getCurrentRow().validate();
                                } catch (RowValException ex) {
                                    boolean duyNhat = false;
                                    Object[] objs = ex.getDetails();
                                    if (objs != null) {
                                        for (Object obj : objs) {
                                            if (obj instanceof
                                                RowValException) {
                                                RowValException e =
                                                    (RowValException)obj;
                                                Object[] detailObjs =
                                                    e.getErrorParameters();
                                                for (Object detailObj :
                                                     detailObjs) {
                                                    if (detailObj instanceof
                                                        String &&
                                                        "validateDuyNhat".equals(detailObj)) {
                                                        duyNhat = true;
                                                        String errorString =
                                                            Utils.getResourceBundle("GIA_TRI_KHONG_DUY_NHAT");
                                                        FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                                      errorString,
                                                                                                                      errorString));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (duyNhat == false) {
                                        throw ex;
                                    }
                                }
                                String expression =
                                    (String)truongTtRow.getAttribute("Expression");
                                if (expression != null &&
                                    expression.isEmpty() == false) {
                                    if (valString.matches(expression) ==
                                        false) {
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                String errorString =
                                    Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                              errorString,
                                                                                              errorString));
                            }
                        } else {
                            gtDvTtView1Iterator.getCurrentRow().setAttribute("ValVarchar",
                                                                             null);
                        }
                    }
                    if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                        if (valObject != null &&
                            valObject.toString().isEmpty() == false) {
                            try {
                                String valString = valObject.toString().trim();
                                gtDvTtView1Iterator.getCurrentRow().setAttribute("ValVarchar",
                                                                                 valString);
                                try {
                                    gtDvTtView1Iterator.getCurrentRow().validate();
                                } catch (RowValException ex) {
                                    boolean duyNhat = false;
                                    Object[] objs = ex.getDetails();
                                    if (objs != null) {
                                        for (Object obj : objs) {
                                            if (obj instanceof
                                                RowValException) {
                                                RowValException e =
                                                    (RowValException)obj;
                                                Object[] detailObjs =
                                                    e.getErrorParameters();
                                                for (Object detailObj :
                                                     detailObjs) {
                                                    if (detailObj instanceof
                                                        String &&
                                                        "validateDuyNhat".equals(detailObj)) {
                                                        duyNhat = true;
                                                        String errorString =
                                                            Utils.getResourceBundle("GIA_TRI_KHONG_DUY_NHAT");
                                                        FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                                      errorString,
                                                                                                                      errorString));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (duyNhat == false) {
                                        throw ex;
                                    }
                                }
                                String expression =
                                    (String)truongTtRow.getAttribute("Expression");
                                if (expression != null &&
                                    expression.isEmpty() == false) {
                                    if (valString.matches(expression) ==
                                        false) {
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                String errorString =
                                    Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                              errorString,
                                                                                              errorString));
                            }
                        } else {
                            gtDvTtView1Iterator.getCurrentRow().setAttribute("ValVarchar",
                                                                             null);
                        }
                    }
                    if (kieu == Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                        if (valObject != null &&
                            valObject.toString().isEmpty() == false) {
                            try {
                                String valString = valObject.toString().trim();
                                gtDvTtView1Iterator.getCurrentRow().setAttribute("ValVarchar",
                                                                                 valString);
                                try {
                                    gtDvTtView1Iterator.getCurrentRow().validate();
                                } catch (RowValException ex) {
                                    boolean duyNhat = false;
                                    Object[] objs = ex.getDetails();
                                    if (objs != null) {
                                        for (Object obj : objs) {
                                            if (obj instanceof
                                                RowValException) {
                                                RowValException e =
                                                    (RowValException)obj;
                                                Object[] detailObjs =
                                                    e.getErrorParameters();
                                                for (Object detailObj :
                                                     detailObjs) {
                                                    if (detailObj instanceof
                                                        String &&
                                                        "validateDuyNhat".equals(detailObj)) {
                                                        duyNhat = true;
                                                        String errorString =
                                                            Utils.getResourceBundle("GIA_TRI_KHONG_DUY_NHAT");
                                                        FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                                      errorString,
                                                                                                                      errorString));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (duyNhat == false) {
                                        throw ex;
                                    }
                                }
                                String expression =
                                    (String)truongTtRow.getAttribute("Expression");
                                if (expression != null &&
                                    expression.isEmpty() == false) {
                                    if (valString.matches(expression) ==
                                        false) {
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                String errorString =
                                    Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                              errorString,
                                                                                              errorString));
                            }
                        } else {
                            gtDvTtView1Iterator.getCurrentRow().setAttribute("ValVarchar",
                                                                             null);
                        }
                    }
                    if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                        if (valObject != null &&
                            valObject.toString().isEmpty() == false) {
                            try {
                                java.util.Date javaDate =
                                    (java.util.Date)valObject;
                                Timestamp timestamp =
                                    new Timestamp(javaDate.getTime());
                                oracle.jbo.domain.Date valDate =
                                    new oracle.jbo.domain.Date(timestamp);
                                gtDvTtView1Iterator.getCurrentRow().setAttribute("ValDate",
                                                                                 valDate);
                                try {
                                    gtDvTtView1Iterator.getCurrentRow().validate();
                                } catch (RowValException ex) {
                                    boolean duyNhat = false;
                                    Object[] objs = ex.getDetails();
                                    if (objs != null) {
                                        for (Object obj : objs) {
                                            if (obj instanceof
                                                RowValException) {
                                                RowValException e =
                                                    (RowValException)obj;
                                                Object[] detailObjs =
                                                    e.getErrorParameters();
                                                for (Object detailObj :
                                                     detailObjs) {
                                                    if (detailObj instanceof
                                                        String &&
                                                        "validateDuyNhat".equals(detailObj)) {
                                                        duyNhat = true;
                                                        String errorString =
                                                            Utils.getResourceBundle("GIA_TRI_KHONG_DUY_NHAT");
                                                        FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                                      errorString,
                                                                                                                      errorString));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (duyNhat == false) {
                                        throw ex;
                                    }
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                String errorString =
                                    Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                              errorString,
                                                                                              errorString));
                            }
                        } else {

                            gtDvTtView1Iterator.getCurrentRow().setAttribute("ValDate",
                                                                             null);
                        }
                    }
                    if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                        if (valObject != null &&
                            valObject.toString().isEmpty() == false) {
                            try {
                            String valString = (String)valObject;
                            ClobDomain valClob = new ClobDomain(valString);
                            gtDvTtView1Iterator.getCurrentRow().remove();
                            NameValuePairs nvp = new NameValuePairs();
                            nvp.setAttribute("DlctTruongTtId",
                                             ((DBSequence)truongTtRow.getAttribute("Id")).getSequenceNumber());
                            nvp.setAttribute("DuyNhat",
                                             truongTtRow.getAttribute("DuyNhat"));
                            nvp.setAttribute("ValClob", valClob);
                            Row row=gtDvTtView1Iterator.getViewObject().createAndInitRow(nvp);
                            valueChangeEvent.getComponent().setId(UPDATE_ID_PREFIX+row.getKey().toStringFormat(false));
                            gtDvTtView1Iterator.executeQuery();
                            } catch (Exception e) {
                                e.printStackTrace();
                                String errorString =
                                    Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                              errorString,
                                                                                              errorString));
                            }
                        } else {
                            gtDvTtView1Iterator.getCurrentRow().remove();
                            NameValuePairs nvp = new NameValuePairs();
                            nvp.setAttribute("DlctTruongTtId",
                                             ((DBSequence)truongTtRow.getAttribute("Id")).getSequenceNumber());
                            nvp.setAttribute("DuyNhat",
                                             truongTtRow.getAttribute("DuyNhat"));
                            Row row=gtDvTtView1Iterator.getViewObject().createAndInitRow(nvp);
                            valueChangeEvent.getComponent().setId(UPDATE_ID_PREFIX+row.getKey().toStringFormat(false));
                            gtDvTtView1Iterator.executeQuery();
                        }
                    }
                    if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                        UploadedFile file = (UploadedFile)valObject;
                        if (file != null) {
                            if (Utils.checkDefaultFileExtension(file.getFilename()) ==
                                false) {
                            String errorString =
                                Utils.getResourceBundle("SAI_DINH_DANG_FILE") +
                                "(" + Utils.getDefaultFileExtension() + ")";
                                ((RichInputFile)valueChangeEvent.getComponent()).resetValue();
                                FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                              errorString,
                                                                                              errorString));
                            } else {
                                try {
                                    BlobDomain blob = new BlobDomain();
                                    InputStream in = file.getInputStream();
                                    OutputStream out =
                                        blob.getBinaryOutputStream();
                                    byte[] buffer = new byte[1024];
                                    int size = 0;
                                    while ((size = in.read(buffer)) != -1) {
                                        out.write(buffer, 0, size);
                                    }
                                    in.close();
                                    out.flush();
                                    gtDvTtView1Iterator.getCurrentRow().setAttribute("ValVarchar",
                                                                                     file.getFilename());
                                    gtDvTtView1Iterator.getCurrentRow().setAttribute("ValNumber",
                                                                                     null);
                                    gtDvTtView1Iterator.getCurrentRow().setAttribute("ValBlob",
                                                                                     blob);
                                    UIComponent downloadComponent =
                                        valueChangeEvent.getComponent().findComponent(UPDATE_ID_PREFIX +
                                                                                      rowKey +
                                                                                      FILE_DOWNLOAD_ID_SUBFIX);
                                    if (downloadComponent != null &&
                                        downloadComponent instanceof
                                        RichCommandLink) {
                                        RichCommandLink commandLink =
                                            (RichCommandLink)downloadComponent;
                                        commandLink.setText(file.getFilename());
                                        AdfFacesContext.getCurrentInstance().addPartialTarget(commandLink);
                                    }
                                    UIComponent groupComponent =
                                        valueChangeEvent.getComponent().findComponent(UPDATE_ID_PREFIX +
                                                                                      rowKey +
                                                                                      FILE_GROUP_ID_SUBFIX);
                                    if (groupComponent != null &&
                                        groupComponent instanceof
                                        RichPanelGroupLayout) {
                                        RichPanelGroupLayout groupLayout =
                                            (RichPanelGroupLayout)groupComponent;
                                        groupLayout.setVisible(true);
                                        AdfFacesContext.getCurrentInstance().addPartialTarget(groupLayout);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    String errorString =
                                        Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                    FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                  errorString,
                                                                                                  errorString));
                                }
                            }
                        } else {
                            gtDvTtView1Iterator.getCurrentRow().setAttribute("ValVarchar",
                                                                             null);
                            gtDvTtView1Iterator.getCurrentRow().setAttribute("ValNumber",
                                                                             null);
                            gtDvTtView1Iterator.getCurrentRow().setAttribute("ValBlob",
                                                                             null);
                            UIComponent groupComponent =
                                valueChangeEvent.getComponent().findComponent(UPDATE_ID_PREFIX +
                                                                              rowKey +
                                                                              FILE_GROUP_ID_SUBFIX);
                            if (groupComponent != null &&
                                groupComponent instanceof
                                RichPanelGroupLayout) {
                                RichPanelGroupLayout groupLayout =
                                    (RichPanelGroupLayout)groupComponent;
                                groupLayout.setVisible(false);
                                AdfFacesContext.getCurrentInstance().addPartialTarget(groupLayout);
                            }
                        }
                    }
                    if (kieu == Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
                        UploadedFile file = (UploadedFile)valObject;
                        if (file != null) {
                            if (Utils.checkDefaultImageExtension(file.getFilename()) ==
                                false) {
                            String errorString =
                                Utils.getResourceBundle("SAI_DINH_DANG_FILE") +
                                "(" + Utils.getDefaultImageExtension() + ")";
                                ((RichInputFile)valueChangeEvent.getComponent()).resetValue();
                                FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                              errorString,
                                                                                              errorString));
                            } else {
                                try {
                                    BlobDomain blob = new BlobDomain();
                                    InputStream in = file.getInputStream();
                                    OutputStream out =
                                        blob.getBinaryOutputStream();
                                    byte[] buffer = new byte[1024];
                                    int size = 0;
                                    while ((size = in.read(buffer)) != -1) {
                                        out.write(buffer, 0, size);
                                    }
                                    in.close();
                                    out.flush();
                                    gtDvTtView1Iterator.getCurrentRow().setAttribute("ValVarchar",
                                                                                     file.getFilename());
                                    gtDvTtView1Iterator.getCurrentRow().setAttribute("ValNumber",
                                                                                     null);
                                    gtDvTtView1Iterator.getCurrentRow().setAttribute("ValBlob",
                                                                                     blob);
                                    UIComponent downloadComponent =
                                        valueChangeEvent.getComponent().findComponent(UPDATE_ID_PREFIX +
                                                                                      rowKey +
                                                                                      FILE_DOWNLOAD_ID_SUBFIX);
                                    if (downloadComponent != null &&
                                        downloadComponent instanceof
                                        RichCommandLink) {
                                        RichCommandLink commandLink =
                                            (RichCommandLink)downloadComponent;
                                        commandLink.setText(file.getFilename());
                                        AdfFacesContext.getCurrentInstance().addPartialTarget(commandLink);
                                    }
                                    UIComponent groupComponent =
                                        valueChangeEvent.getComponent().findComponent(UPDATE_ID_PREFIX +
                                                                                      rowKey +
                                                                                      FILE_GROUP_ID_SUBFIX);
                                    if (groupComponent != null &&
                                        groupComponent instanceof
                                        RichPanelGroupLayout) {
                                        RichPanelGroupLayout groupLayout =
                                            (RichPanelGroupLayout)groupComponent;
                                        groupLayout.setVisible(true);
                                        AdfFacesContext.getCurrentInstance().addPartialTarget(groupLayout);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    String errorString =
                                        Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                    FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                                 new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                  errorString,
                                                                                                  errorString));
                                }
                            }
                        } else {
                            gtDvTtView1Iterator.getCurrentRow().setAttribute("ValVarchar",
                                                                             null);
                            gtDvTtView1Iterator.getCurrentRow().setAttribute("ValNumber",
                                                                             null);
                            gtDvTtView1Iterator.getCurrentRow().setAttribute("ValBlob",
                                                                             null);
                            UIComponent groupComponent =
                                valueChangeEvent.getComponent().findComponent(UPDATE_ID_PREFIX +
                                                                              rowKey +
                                                                              FILE_GROUP_ID_SUBFIX);
                            if (groupComponent != null &&
                                groupComponent instanceof
                                RichPanelGroupLayout) {
                                RichPanelGroupLayout groupLayout =
                                    (RichPanelGroupLayout)groupComponent;
                                groupLayout.setVisible(false);
                                AdfFacesContext.getCurrentInstance().addPartialTarget(groupLayout);
                            }
                        }
                    }
                    if (kieu ==
                        Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
                        if (valObject != null &&
                            valObject.toString().isEmpty() == false) {
                            try {
                                Number valNumber = new Number(valObject);
                                gtDvTtView1Iterator.getCurrentRow().setAttribute("DlctSanGiaoDichId",
                                                                                 valNumber);
                            } catch (Exception e) {
                                e.printStackTrace();
                                String errorString =
                                    Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                              errorString,
                                                                                              errorString));
                            }
                        } else {
                            gtDvTtView1Iterator.getCurrentRow().setAttribute("DlctSanGiaoDichId",
                                                                             null);
                        }
                    }
                    if (kieu ==
                        Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId()) {
                        if (valObject != null &&
                            valObject.toString().isEmpty() == false) {
                            try {
                                Number valNumber = new Number(valObject);
                                gtDvTtView1Iterator.getCurrentRow().setAttribute("DlctLoaiChungKhoanId",
                                                                                 valNumber);
                            } catch (Exception e) {
                                e.printStackTrace();
                                String errorString =
                                    Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                FacesContext.getCurrentInstance().addMessage(valueChangeEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                              errorString,
                                                                                              errorString));
                            }
                        } else {
                            gtDvTtView1Iterator.getCurrentRow().setAttribute("DlctLoaiChungKhoanId",
                                                                             null);
                        }
                    }
                }
            }
        }
    }

    public void changeLoaiDonVi(ValueChangeEvent valueChangeEvent) {
        List<String> listLoaiDonViId =
            (List<String>)valueChangeEvent.getNewValue();

        searchNgonNgu(listLoaiDonViId);
        List<SelectItem> listSelectItem = new ArrayList();
        DCIteratorBinding ngonNguView1Iterator =
            Utils.getIteratorBinding("DlctNgonNguView1Iterator");
        ngonNguView1Iterator.setRangeSize(-1);
        Row[] rows = ngonNguView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        for (int i = 0; i < rows.length; i++) {
            String id = ((DBSequence)rows[i].getAttribute("Id")).toString();
            String ma = (String)rows[i].getAttribute("Ma");
            String ten = (String)rows[i].getAttribute("Ten");
            SelectItem si = new SelectItem();
            si.setValue(id);
            si.setLabel(ma + "_" + ten);
            listSelectItem.add(si);
        }
        UISelectItems uiSelectItems = new UISelectItems();
        uiSelectItems.setValue(listSelectItem);
        selectNgonNgu.setValue(null);
        selectNgonNgu.getChildren().clear();
        selectNgonNgu.getChildren().add(uiSelectItems);
        createUpdateForm(listLoaiDonViId, null);
    }

    public void changeNgonNgu(ValueChangeEvent valueChangeEvent) {
        List<String> listLoaiDonViId =
            (List<String>)selectLoaiDonVi.getValue();
        List<String> listNgonNguId =
            (List<String>)valueChangeEvent.getNewValue();
        createUpdateForm(listLoaiDonViId, listNgonNguId);
    }

    public void fileDownload(ActionEvent actionEvent) {
        String rowKey = actionEvent.getComponent().getId();
        if (rowKey.startsWith(UPDATE_ID_PREFIX))
            rowKey = rowKey.substring(UPDATE_ID_PREFIX.length());
        if (rowKey.endsWith(FILE_DOWNLOAD_ID_SUBFIX))
            rowKey =
                    rowKey.substring(0, rowKey.length() - FILE_DOWNLOAD_ID_SUBFIX.length());
        DCIteratorBinding gtDvTtView1Iterator =
            Utils.getIteratorBinding("DlctGtDvTtView1Iterator");
        gtDvTtView1Iterator.setCurrentRowWithKey(rowKey);
        Row truongTtRow =
            (Row)gtDvTtView1Iterator.getCurrentRow().getAttribute("DlctTruongTtView");
        if (truongTtRow != null) {
            Number id =
                ((DBSequence)truongTtRow.getAttribute("Id")).getSequenceNumber();
            Number kieuDuLieu = (Number)truongTtRow.getAttribute("KieuDuLieu");
            if (id != null && kieuDuLieu != null) {
                int kieu = kieuDuLieu.intValue();
                if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                    BlobDomain blob =
                        (BlobDomain)gtDvTtView1Iterator.getCurrentRow().getAttribute("ValBlob");
                    Row fileViewRow =
                        (Row)gtDvTtView1Iterator.getCurrentRow().getAttribute("HtFileView");
                    if (blob == null) {
                        if (fileViewRow != null) {
                            String duongDan =
                                (String)fileViewRow.getAttribute("DuongDan");
                            if (duongDan != null) {
                                String rootString =
                                    Utils.ENUM_CAU_HINH_KHOA.FILE_ROOT.getValue("HtCauHinhView1Iterator");
                                if (rootString != null) {
                                    File rootFile = new File(rootString);
                                    File thisFile =
                                        new File(rootFile, duongDan);
                                    if (thisFile.exists() == false) {
                                        System.out.println("file khong ton tai");
                                        return;
                                    } else {
                                        fileDownloadButton.getAttributes().put("rowKey",
                                                                               rowKey);
                                        fileDownloadButton.setText((String)fileViewRow.getAttribute("TenFile"));

                                        FacesContext context =
                                            FacesContext.getCurrentInstance();
                                        ExtendedRenderKitService erks =
                                            Service.getService(context.getRenderKit(),
                                                               ExtendedRenderKitService.class);

                                        erks.addScript(context,
                                                       "customHandler();");
                                    }
                                }
                            }
                        } else {
                            return;
                        }
                    } else {
                        fileDownloadButton.getAttributes().put("rowKey",
                                                               rowKey);
                        fileDownloadButton.setText((String)gtDvTtView1Iterator.getCurrentRow().getAttribute("ValVarchar"));

                        FacesContext context =
                            FacesContext.getCurrentInstance();
                        ExtendedRenderKitService erks =
                            Service.getService(context.getRenderKit(),
                                               ExtendedRenderKitService.class);

                        erks.addScript(context, "customHandler();");
                    }
                }
                if (kieu == Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
                    BlobDomain blob =
                        (BlobDomain)gtDvTtView1Iterator.getCurrentRow().getAttribute("ValBlob");
                    Row fileViewRow =
                        (Row)gtDvTtView1Iterator.getCurrentRow().getAttribute("HtFileView");
                    if (blob == null) {
                        if (fileViewRow != null) {
                            String duongDan =
                                (String)fileViewRow.getAttribute("DuongDan");
                            if (duongDan != null) {
                                String rootString =
                                    Utils.ENUM_CAU_HINH_KHOA.FILE_ROOT.getValue("HtCauHinhView1Iterator");
                                if (rootString != null) {
                                    File rootFile = new File(rootString);
                                    File thisFile =
                                        new File(rootFile, duongDan);
                                    if (thisFile.exists() == false) {
                                        System.out.println("file khong ton tai");
                                        return;
                                    } else {
                                        fileDownloadButton.getAttributes().put("rowKey",
                                                                               rowKey);
                                        fileDownloadButton.setText((String)fileViewRow.getAttribute("TenFile"));

                                        FacesContext context =
                                            FacesContext.getCurrentInstance();
                                        ExtendedRenderKitService erks =
                                            Service.getService(context.getRenderKit(),
                                                               ExtendedRenderKitService.class);

                                        erks.addScript(context,
                                                       "customHandler();");
                                    }
                                }
                            }
                        } else {
                            return;
                        }
                    } else {
                        fileDownloadButton.getAttributes().put("rowKey",
                                                               rowKey);
                        fileDownloadButton.setText((String)gtDvTtView1Iterator.getCurrentRow().getAttribute("ValVarchar"));

                        FacesContext context =
                            FacesContext.getCurrentInstance();
                        ExtendedRenderKitService erks =
                            Service.getService(context.getRenderKit(),
                                               ExtendedRenderKitService.class);

                        erks.addScript(context, "customHandler();");
                    }
                }
            }
        }
    }

    public void fileDownload(FacesContext facesContext,
                             OutputStream outputStream) {
        String rowKey =
            (String)fileDownloadButton.getAttributes().get("rowKey");
        DCIteratorBinding gtDvTtView1Iterator =
            Utils.getIteratorBinding("DlctGtDvTtView1Iterator");
        gtDvTtView1Iterator.setCurrentRowWithKey(rowKey);
        Row truongTtRow =
            (Row)gtDvTtView1Iterator.getCurrentRow().getAttribute("DlctTruongTtView");
        if (truongTtRow != null) {
            Number id =
                ((DBSequence)truongTtRow.getAttribute("Id")).getSequenceNumber();
            Number kieuDuLieu = (Number)truongTtRow.getAttribute("KieuDuLieu");
            if (id != null && kieuDuLieu != null) {
                int kieu = kieuDuLieu.intValue();
                if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                    BlobDomain blob =
                        (BlobDomain)gtDvTtView1Iterator.getCurrentRow().getAttribute("ValBlob");
                    Row fileViewRow =
                        (Row)gtDvTtView1Iterator.getCurrentRow().getAttribute("HtFileView");
                    if (blob == null) {
                        if (fileViewRow != null) {
                            String duongDan =
                                (String)fileViewRow.getAttribute("DuongDan");
                            if (duongDan != null) {
                                String rootString =
                                    Utils.ENUM_CAU_HINH_KHOA.FILE_ROOT.getValue("HtCauHinhView1Iterator");
                                if (rootString != null) {
                                    File rootFile = new File(rootString);
                                    File thisFile =
                                        new File(rootFile, duongDan);
                                    if (thisFile.exists()) {
                                        try {
                                            FileInputStream in =
                                                new FileInputStream(thisFile);
                                            byte buffer[] = new byte[1024];
                                            int size = 0;
                                            while ((size = in.read(buffer)) !=
                                                   -1) {
                                                outputStream.write(buffer, 0,
                                                                   size);
                                            }
                                            in.close();
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        } finally {
                                            if (outputStream != null) {
                                                try {
                                                    outputStream.flush();
                                                    outputStream.close();
                                                } catch (Exception e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {

                        try {
                            InputStream in = blob.getBinaryStream();
                            byte buffer[] = new byte[1024];
                            int size = 0;
                            while ((size = in.read(buffer)) != -1) {
                                outputStream.write(buffer, 0, size);
                            }
                            in.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        } finally {
                            if (outputStream != null) {
                                try {
                                    outputStream.flush();
                                    outputStream.close();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                }
                if (kieu == Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
                    BlobDomain blob =
                        (BlobDomain)gtDvTtView1Iterator.getCurrentRow().getAttribute("ValBlob");
                    Row fileViewRow =
                        (Row)gtDvTtView1Iterator.getCurrentRow().getAttribute("HtFileView");
                    if (blob == null) {
                        if (fileViewRow != null) {
                            String duongDan =
                                (String)fileViewRow.getAttribute("DuongDan");
                            if (duongDan != null) {
                                String rootString =
                                    Utils.ENUM_CAU_HINH_KHOA.FILE_ROOT.getValue("HtCauHinhView1Iterator");
                                if (rootString != null) {
                                    File rootFile = new File(rootString);
                                    File thisFile =
                                        new File(rootFile, duongDan);
                                    if (thisFile.exists()) {
                                        try {
                                            FileInputStream in =
                                                new FileInputStream(thisFile);
                                            byte buffer[] = new byte[1024];
                                            int size = 0;
                                            while ((size = in.read(buffer)) !=
                                                   -1) {
                                                outputStream.write(buffer, 0,
                                                                   size);
                                            }
                                            in.close();
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        } finally {
                                            if (outputStream != null) {
                                                try {
                                                    outputStream.flush();
                                                    outputStream.close();
                                                } catch (Exception e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {

                        try {
                            InputStream in = blob.getBinaryStream();
                            byte buffer[] = new byte[1024];
                            int size = 0;
                            while ((size = in.read(buffer)) != -1) {
                                outputStream.write(buffer, 0, size);
                            }
                            in.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        } finally {
                            if (outputStream != null) {
                                try {
                                    outputStream.flush();
                                    outputStream.close();
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    private void searchNgonNgu(List<String> listLoaiDonViId) {
        if (listLoaiDonViId != null && listLoaiDonViId.size() > 0) {
            List<AdvancedSearchGroup> listASG = new ArrayList();
            AdvancedSearchGroup asg = new AdvancedSearchGroup();
            listASG.add(asg);
            AdvancedSearchItem asi = new AdvancedSearchItem();
            asg.getListChildren().add(asi);
            asi.setItemName("TrangThai");
            asi.setRequired(true);
            asi.getListValue().add(0,
                                   new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
            asi = new AdvancedSearchItem();
            asi.setItemName("DlctLdvNnView");
            asi.setRequired(true);
            asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
            AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
            asi.getListChildren().add(asgChild);
            AdvancedSearchItem asiChild = new AdvancedSearchItem();
            asgChild.getListChildren().add(asiChild);
            asiChild.setItemName("DlctLoaiDonViId");
            asiChild.setRequired(true);
            asiChild.setOperator(AdvancedSearchItem.OPER_IN);
            if (listLoaiDonViId != null) {
                for (String loaiDonViId : listLoaiDonViId) {
                    Number idNumber = null;
                    try {
                        idNumber = new Number(loaiDonViId);
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }

                    if (idNumber != null) {
                        asiChild.getListValue().add(idNumber);
                    }
                }
            }
            Utils.searchadvanced("DlctNgonNguView1Iterator", listASG);
        }
    }

    private void searchTruongTt(List<String> listLoaiDonViId) {
        if (listLoaiDonViId != null && listLoaiDonViId.size() > 0) {
            List<AdvancedSearchGroup> listASG = new ArrayList();
            AdvancedSearchGroup asg = new AdvancedSearchGroup();
            listASG.add(asg);
            AdvancedSearchItem asi = new AdvancedSearchItem();
            asg.getListChildren().add(asi);
            asi.setItemName("TrangThai");
            asi.setRequired(true);
            asi.getListValue().add(0,
                                   new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
            asi = new AdvancedSearchItem();
            asg.getListChildren().add(asi);
            asi.setItemName("DlctLoaiTruongTt");
            asi.setRequired(true);
            asi.getListValue().add(0,
                                   new Number(Utils.ENUM_LOAI_TRUONG_TT.DON_VI.getId()));
            asi = new AdvancedSearchItem();
            asg.getListChildren().add(asi);
            asi.setItemName("DlctLdvTtView");
            asi.setRequired(true);
            asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
            AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
            asi.getListChildren().add(asgChild);
            AdvancedSearchItem asiChild = new AdvancedSearchItem();
            asgChild.getListChildren().add(asiChild);
            asiChild.setItemName("DlctLoaiDonViId");
            asiChild.setRequired(true);
            asiChild.setOperator(AdvancedSearchItem.OPER_IN);
            if (listLoaiDonViId != null) {
                for (String loaiDonViId : listLoaiDonViId) {
                    Number idNumber = null;
                    try {
                        idNumber = new Number(loaiDonViId);
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }

                    if (idNumber != null) {
                        asiChild.getListValue().add(idNumber);
                    }
                }
            }
            Utils.searchadvanced("DlctTruongTtView1Iterator", listASG);
        }
    }

    private void createUpdateForm(List<String> listLoaiDonViId,
                                  List<String> listNgonNguId) {
        updatePanel.getChildren().clear();
        if (listLoaiDonViId != null && listLoaiDonViId.size() > 0 &&
            listNgonNguId != null && listNgonNguId.size() > 0) {
            updatePanel.setVisible(true);

            DCIteratorBinding ngonNguView1Iterator =
                Utils.getIteratorBinding("DlctNgonNguView1Iterator");
            DCIteratorBinding gtDvTtView1Iterator =
                Utils.getIteratorBinding("DlctGtDvTtView1Iterator");

            Map<String, RichPanelFormLayout> mapNgonNguLayout = new HashMap();
            for (String ngonNguId : listNgonNguId) {
                ngonNguView1Iterator.setCurrentRowWithKeyValue(ngonNguId);
                RichShowDetailItem showDetailItem = new RichShowDetailItem();
                showDetailItem.setImmediate(true);
                showDetailItem.setText((String)ngonNguView1Iterator.getCurrentRow().getAttribute("Ten"));
                RichPanelFormLayout formLayout = new RichPanelFormLayout();
                mapNgonNguLayout.put(ngonNguId, formLayout);
                showDetailItem.getChildren().add(formLayout);
                updatePanel.getChildren().add(showDetailItem);
            }

            Map<Number, Object> mapValue = new HashMap();
            Map<Number, String> mapGtKey = new HashMap();
            gtDvTtView1Iterator.setRangeSize(-1);
            Row[] rows = gtDvTtView1Iterator.getAllRowsInRange();
            if (rows == null) {
                rows = new Row[] { };
            }
            for (int i = 0; i < rows.length; i++) {
                Row truongTtRow =
                    (Row)rows[i].getAttribute("DlctTruongTtView");
                if (truongTtRow != null) {
                    Number id =
                        ((DBSequence)truongTtRow.getAttribute("Id")).getSequenceNumber();
                    Number kieuDuLieu =
                        (Number)truongTtRow.getAttribute("KieuDuLieu");
                    Number truongTtTu =
                        (Number)truongTtRow.getAttribute("DlctTruongTtTuId");
                    if (id != null && kieuDuLieu != null &&
                        truongTtTu == null) {
                        int kieu = kieuDuLieu.intValue();
                        mapGtKey.put(id,
                                     rows[i].getKey().toStringFormat(false));
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                            Number valNumber =
                                (Number)rows[i].getAttribute("ValNumber");
                            if (valNumber != null) {
                                mapValue.put(id, valNumber.toString());
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                            String valVarchar =
                                (String)rows[i].getAttribute("ValVarchar");
                            if (valVarchar != null) {
                                mapValue.put(id, valVarchar);
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                            String valVarchar =
                                (String)rows[i].getAttribute("ValVarchar");
                            if (valVarchar != null) {
                                mapValue.put(id, valVarchar);
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                            String valVarchar =
                                (String)rows[i].getAttribute("ValVarchar");
                            if (valVarchar != null) {
                                mapValue.put(id, valVarchar);
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                            oracle.jbo.domain.Date valDate =
                                (oracle.jbo.domain.Date)rows[i].getAttribute("ValDate");
                            if (valDate != null) {
                                java.util.Date date = valDate.dateValue();
                                mapValue.put(id, date);
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                            ClobDomain valClob =
                                (ClobDomain)rows[i].getAttribute("ValClob");
                            if (valClob != null) {
                                mapValue.put(id, valClob.toString());
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                            Row htFileRow =
                                (Row)rows[i].getAttribute("HtFileView");
                            if (htFileRow != null) {
                                mapValue.put(id,
                                             htFileRow.getAttribute("TenFile"));
                            }
                        }
                        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
                            Row htFileRow =
                                (Row)rows[i].getAttribute("HtFileView");
                            if (htFileRow != null) {
                                mapValue.put(id,
                                             htFileRow.getAttribute("TenFile"));
                            }
                        }
                        if (kieu ==
                            Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId()) {
                            Number valNumber =
                                (Number)rows[i].getAttribute("DlctLoaiChungKhoanId");
                            if (valNumber != null) {
                                mapValue.put(id, valNumber.toString());
                            }
                        }
                        if (kieu ==
                            Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
                            Number valNumber =
                                (Number)rows[i].getAttribute("DlctSanGiaoDichId");
                            if (valNumber != null) {
                                mapValue.put(id, valNumber.toString());
                            }
                        }
                    }
                }
            }

            searchTruongTt(listLoaiDonViId);
            DCIteratorBinding truongTtView1Iterator =
                Utils.getIteratorBinding("DlctTruongTtView1Iterator");
            truongTtView1Iterator.setRangeSize(-1);
            rows = truongTtView1Iterator.getAllRowsInRange();
            if (rows == null) {
                rows = new Row[] { };
            }
            Map<String, Row> mapTruongTtRoot = new HashMap();
            for (int i = 0; i < rows.length; i++) {
                Row rowParent =
                    (Row)rows[i].getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                if (rowParent == null) {
                    String rowKey = rows[i].getKey().toStringFormat(false);
                    mapTruongTtRoot.put(rowKey, rows[i]);
                }
            }
            for (int i = 0; i < rows.length; i++) {
                Number id =
                    ((DBSequence)rows[i].getAttribute("Id")).getSequenceNumber();
                String ten = (String)rows[i].getAttribute("TenTruong");
                Number batBuoc = (Number)rows[i].getAttribute("BatBuoc");
                Number duyNhat = (Number)rows[i].getAttribute("DuyNhat");
                Number kieuDuLieu = (Number)rows[i].getAttribute("KieuDuLieu");
                Number ngonNguId =
                    (Number)rows[i].getAttribute("DlctNgonNguId");
                Row loopRow = rows[i];
                Row rootRow = null;
                while (loopRow != null) {
                    rootRow = loopRow;
                    loopRow =
                            (Row)loopRow.getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                }
                String rowKey = rows[i].getKey().toStringFormat(false);
                String rootKey = rootRow.getKey().toStringFormat(false);
                if (batBuoc != null && kieuDuLieu != null &&
                    ngonNguId != null) {
                    RichPanelFormLayout formLayout =
                        mapNgonNguLayout.get(String.valueOf(ngonNguId.intValue()));
                    if (rowKey.equals(rootKey) == false) {
                        Row checkRow = mapTruongTtRoot.get(rootKey);
                        if (checkRow == null) {
                            Number rootId =
                                ((DBSequence)rootRow.getAttribute("Id")).getSequenceNumber();
                            String gtKey = mapGtKey.get(rootId);
                            Object value = mapValue.get(rootId);
                            if (gtKey == null) {
                                NameValuePairs nvp = new NameValuePairs();
                                nvp.setAttribute("DlctTruongTtId", rootId);
                                nvp.setAttribute("DuyNhat", duyNhat);
                                Row row =
                                    gtDvTtView1Iterator.getViewObject().createAndInitRow(nvp);
                                gtKey = row.getKey().toStringFormat(false);
                                gtDvTtView1Iterator.executeQuery();
                            }
                            if (formLayout != null) {
                                List<UIComponent> components =
                                    createInputComponent(UPDATE_ID_PREFIX +
                                                         gtKey, ten, ngonNguId,
                                                         kieuDuLieu.intValue(),
                                                         batBuoc.intValue(),
                                                         value, false);
                                if (components != null) {
                                    formLayout.getChildren().addAll(components);
                                }
                            }
                            mapTruongTtRoot.put(rootKey, rows[i]);
                        } else {
                            Object value = checkRow.getAttribute("TenTruong");
                            if (formLayout != null) {
                                List<UIComponent> components =
                                    createInputComponent(null, ten, ngonNguId,
                                                         Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId(),
                                                         Utils.ENUM_BAT_BUOC.KHONG_BAT_BUOC.getId(),
                                                         value, true);
                                if (components != null) {
                                    formLayout.getChildren().addAll(components);
                                }
                            }
                        }
                    } else {
                        String gtKey = mapGtKey.get(id);
                        Object value = mapValue.get(id);
                        if (gtKey == null) {
                            NameValuePairs nvp = new NameValuePairs();
                            nvp.setAttribute("DlctTruongTtId", id);
                            nvp.setAttribute("DuyNhat", duyNhat);
                            Row row =
                                gtDvTtView1Iterator.getViewObject().createAndInitRow(nvp);
                            gtKey = row.getKey().toStringFormat(false);
                            gtDvTtView1Iterator.executeQuery();
                        }
                        if (formLayout != null) {
                            List<UIComponent> components =
                                createInputComponent(UPDATE_ID_PREFIX + gtKey,
                                                     ten, ngonNguId,
                                                     kieuDuLieu.intValue(),
                                                     batBuoc.intValue(), value,
                                                     false);
                            if (components != null) {
                                formLayout.getChildren().addAll(components);
                            }
                        }
                    }
                }
            }
        } else {
            updatePanel.setVisible(false);
        }
    }

    public void rollback(PopupCanceledEvent popupCanceledEvent) {
        DCIteratorBinding donViView1Iterator =
            Utils.getIteratorBinding("DlctDonViView1Iterator");
        String rowKey = null;
        if (donViView1Iterator.getCurrentRow() != null)
            rowKey =
                    donViView1Iterator.getCurrentRow().getKey().toStringFormat(false);
        donViView1Iterator.getDataControl().getApplicationModule().getTransaction().rollback();
        iteratorFilter();
        if (rowKey != null)
            donViView1Iterator.setCurrentRowWithKey(rowKey);
        Integer pageNum = null;
        try {
            pageNum = new Integer(goToPage.getValue().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (pageNum != null) {
            getValue(pageNum.intValue());
        }
    }

    public void commit(DialogEvent dialogEvent) {
        DCIteratorBinding fileView1Iterator =
            Utils.getIteratorBinding("HtFileView1Iterator");
        DCIteratorBinding dvLdvView1Iterator =
            Utils.getIteratorBinding("DlctDvLdvView1Iterator");
        DCIteratorBinding dvNnView1Iterator =
            Utils.getIteratorBinding("DlctDvNnView1Iterator");
        DCIteratorBinding gtDvTtView1Iterator =
            Utils.getIteratorBinding("DlctGtDvTtView1Iterator");
        List<String> listDelete = new ArrayList();
        gtDvTtView1Iterator.setRangeSize(-1);
        Row[] rows = gtDvTtView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        List<UIComponent> listInvalid = new ArrayList();
        List<UIComponent> listUnique= new ArrayList();
        List<UIComponent> listRequired = new ArrayList();
        for (int i = 0; i < rows.length; i++) {
            UIComponent ui =
                updatePanel.findComponent(UPDATE_ID_PREFIX + rows[i].getKey().toStringFormat(false));
            Row truongTtRow = (Row)rows[i].getAttribute("DlctTruongTtView");
            if (truongTtRow != null && ui != null) {
                Number batBuoc = (Number)truongTtRow.getAttribute("BatBuoc");
                Number kieuDuLieu =
                    (Number)truongTtRow.getAttribute("KieuDuLieu");
                Number truongTtTu =
                    (Number)truongTtRow.getAttribute("DlctTruongTtTuId");
                if (batBuoc != null && kieuDuLieu != null &&
                    truongTtTu == null) {
                    Object value = null;
                    if (kieuDuLieu.intValue() ==
                        Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                        Number valNumber =
                            (Number)rows[i].getAttribute("ValNumber");
                        if (valNumber != null) {
                            value = valNumber.toString();
                        }
                    }
                    if (kieuDuLieu.intValue() ==
                        Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                        String valVarchar =
                            (String)rows[i].getAttribute("ValVarchar");
                        if (valVarchar != null) {
                            value = valVarchar;
                        }
                    }
                    if (kieuDuLieu.intValue() ==
                        Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                        String valVarchar =
                            (String)rows[i].getAttribute("ValVarchar");
                        if (valVarchar != null) {
                            value = valVarchar;
                        }
                    }
                    if (kieuDuLieu.intValue() ==
                        Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                        String valVarchar =
                            (String)rows[i].getAttribute("ValVarchar");
                        if (valVarchar != null) {
                            value = valVarchar;
                        }
                    }
                    if (kieuDuLieu.intValue() ==
                        Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                        oracle.jbo.domain.Date valDate =
                            (oracle.jbo.domain.Date)rows[i].getAttribute("ValDate");
                        if (valDate != null) {
                            java.util.Date date = valDate.dateValue();
                            if (date != null) {
                                value = date;
                            }
                        }
                    }
                    if (kieuDuLieu.intValue() ==
                        Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                        ClobDomain valClob =
                            (ClobDomain)rows[i].getAttribute("ValClob");
                        if (valClob != null) {
                            value = valClob.toString();
                        }
                    }
                    if (kieuDuLieu.intValue() ==
                        Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                        Number trangThai =
                            (Number)rows[i].getAttribute("ValNumber");
                        String tenFile =
                            (String)rows[i].getAttribute("ValVarchar");
                        if (trangThai == null ||
                            trangThai.intValue() == Utils.ENUM_TRANG_THAI.CONG_BO.getId()) {
                            if (tenFile != null) {
                                value = tenFile;
                            } else {
                                Row htFileRow =
                                    (Row)rows[i].getAttribute("HtFileView");
                                if (htFileRow != null) {
                                    value = htFileRow.getAttribute("TenFile");
                                }
                            }
                        }
                    }
                    if (kieuDuLieu.intValue() ==
                        Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
                        Number trangThai =
                            (Number)rows[i].getAttribute("ValNumber");
                        String tenFile =
                            (String)rows[i].getAttribute("ValVarchar");
                        if (trangThai == null ||
                            trangThai.intValue() == Utils.ENUM_TRANG_THAI.CONG_BO.getId()) {
                            if (tenFile != null) {
                                value = tenFile;
                            } else {
                                Row htFileRow =
                                    (Row)rows[i].getAttribute("HtFileView");
                                if (htFileRow != null) {
                                    value = htFileRow.getAttribute("TenFile");
                                }
                            }
                        }
                    }
                    if (kieuDuLieu.intValue() ==
                        Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId()) {
                        Number valNumber =
                            (Number)rows[i].getAttribute("DlctLoaiChungKhoanId");
                        if (valNumber != null) {
                            value = valNumber.toString();
                        }
                    }
                    if (kieuDuLieu.intValue() ==
                        Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
                        Number valNumber =
                            (Number)rows[i].getAttribute("DlctSanGiaoDichId");
                        if (valNumber != null) {
                            value = valNumber.toString();
                        }
                    }
                    if ((batBuoc.intValue() ==
                         Utils.ENUM_BAT_BUOC.KHONG_BAT_BUOC.getId() &&
                         value == null) ||
                        kieuDuLieu.intValue() == Utils.ENUM_KIEU_DU_LIEU.KIEM_TOAN_VIEN.getId() ||
                        kieuDuLieu.intValue() ==
                        Utils.ENUM_KIEU_DU_LIEU.SL_KIEM_TOAN_VIEN.getId() ||
                        kieuDuLieu.intValue() ==
                        Utils.ENUM_KIEU_DU_LIEU.IN_OUT_KIEM_TOAN_VIEN.getId()) {
                        listDelete.add(rows[i].getKey().toStringFormat(false));
                    } else if (batBuoc.intValue() ==
                               Utils.ENUM_BAT_BUOC.BAT_BUOC.getId() &&
                               value == null) {
                        UIXInput input = (UIXInput)ui;
                        input.setValid(false);
                        listRequired.add(ui);
                        String errorString =
                            Utils.getResourceBundle("TRUONG_DU_LIEU_BAT_BUOC");
                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                      errorString,
                                                                                      errorString));

                    }
                    try {
                        rows[i].validate();
                    } catch (RowValException ex) {
                        Object[] objs = ex.getDetails();
                        if (objs != null) {
                            for (Object obj : objs) {
                                if (obj instanceof
                                    RowValException) {
                                    RowValException e =
                                        (RowValException)obj;
                                    Object[] detailObjs =
                                        e.getErrorParameters();
                                    for (Object detailObj :
                                         detailObjs) {
                                        if (detailObj instanceof
                                            String &&
                                            "validateDuyNhat".equals(detailObj)) {
                                            listUnique.add(ui);
                                            String errorString =
                                                Utils.getResourceBundle("GIA_TRI_KHONG_DUY_NHAT");
                                            FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                         new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                          errorString,
                                                                                                          errorString));
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if(value!=null&&(kieuDuLieu.intValue()==Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()||
                       kieuDuLieu.intValue()==Utils.ENUM_KIEU_DU_LIEU.LINK.getId()||
                       kieuDuLieu.intValue()==Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId())){
                        String expression =
                            (String)truongTtRow.getAttribute("Expression");
                        if (expression != null &&
                            expression.isEmpty() == false) {
                            if (value.toString().matches(expression) ==
                                false) {
                                String errorString =
                                    Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                listInvalid.add(ui);
                                FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                              errorString,
                                                                                              errorString));
                            }
                        }
                    }
                } else {
                    listDelete.add(rows[i].getKey().toStringFormat(false));
                }
            } else {
                listDelete.add(rows[i].getKey().toStringFormat(false));
            }
        }
        if (listRequired.size() > 0||listInvalid.size() > 0||listUnique.size()>0) {
            if(listRequired.size() > 0){
            String errorString =
                Utils.getResourceBundle("NHAP_TAT_CA_CAC_TRUONG_DU_LIEU_BAT_BUOC");
            FacesContext.getCurrentInstance().addMessage(dialogEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                         new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                          errorString,
                                                                          errorString));
            }
            if(listInvalid.size() > 0){
            String errorString =
                Utils.getResourceBundle("NHAP_LAI_TAT_CA_CAC_TRUONG_DU_LIEU_KHONG_HOP_LE");
            FacesContext.getCurrentInstance().addMessage(dialogEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                         new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                          errorString,
                                                                          errorString));
            }
            if(listUnique.size() > 0){
            String errorString =
                Utils.getResourceBundle("NHAP_LAI_TAT_CA_CAC_TRUONG_DU_LIEU_DUY_NHAT");
            FacesContext.getCurrentInstance().addMessage(dialogEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                         new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                          errorString,
                                                                          errorString));
            }
            List<UIComponent> listUI=new ArrayList();
            listUI.addAll(listRequired);
            listUI.addAll(listInvalid);
            RichShowDetailItem current = null;
            for (UIComponent ui : updatePanel.getChildren()) {
                if (ui instanceof RichShowDetailItem) {
                    RichShowDetailItem rsdi = (RichShowDetailItem)ui;
                    if (rsdi.isDisclosed()) {
                        current = rsdi;
                    }
                    rsdi.setDisclosed(false);
                }
            }
            UIComponent ui = null;
            int i = 0;
            while (ui == null && i < listUI.size()) {
                ui = listUI.get(i++);
                while (ui != null &&
                       (ui instanceof RichShowDetailItem) == false) {
                    ui = ui.getParent();
                }
                if (ui instanceof RichShowDetailItem) {
                    RichShowDetailItem rsdi = (RichShowDetailItem)ui;
                    rsdi.setDisclosed(true);
                }
            }
            if (i == listUI.size()) {
                current.setDisclosed(true);
            }
        } else {
            boolean createPhysicFile = true;
            List<File> listFileDelete = new ArrayList();
            String rootString =
                Utils.ENUM_CAU_HINH_KHOA.FILE_ROOT.getValue("HtCauHinhView1Iterator");
            if (rootString != null) {
                File rootFile = new File(rootString);
                for (int i = 0; i < rows.length && createPhysicFile; i++) {
                    Row truongTtRow =
                        (Row)rows[i].getAttribute("DlctTruongTtView");
                    if (truongTtRow != null) {
                        Number kieuDuLieu =
                            (Number)truongTtRow.getAttribute("KieuDuLieu");
                        Number truongTtTu =
                            (Number)truongTtRow.getAttribute("DlctTruongTtTuId");
                        if (kieuDuLieu != null && truongTtTu == null) {
                            if (kieuDuLieu.intValue() ==
                                Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                Number trangThai =
                                    (Number)rows[i].getAttribute("ValNumber");
                                String tenFile =
                                    (String)rows[i].getAttribute("ValVarchar");
                                BlobDomain blob =
                                    (BlobDomain)rows[i].getAttribute("ValBlob");
                                if (trangThai == null ||
                                    trangThai.intValue() ==
                                    Utils.ENUM_TRANG_THAI.CONG_BO.getId()) {
                                    if (tenFile != null && blob != null) {
                                        Row htFileRow =
                                            (Row)rows[i].getAttribute("HtFileView");
                                        if (htFileRow != null) {
                                            String duongDan =
                                                (String)htFileRow.getAttribute("DuongDan");
                                            listFileDelete.add(new File(rootFile,
                                                                        duongDan));
                                            fileView1Iterator.removeRowWithKey(htFileRow.getKey().toStringFormat(false));
                                        }
                                        NameValuePairs nvp =
                                            new NameValuePairs();
                                        nvp.setAttribute("TenFile", tenFile);
                                        nvp.setAttribute("MaUngDung",
                                                         Utils.ENUM_MA_UNG_DUNG.DLCT.getMaUngDung());
                                        htFileRow =
                                                fileView1Iterator.getViewObject().createAndInitRow(nvp);
                                        fileView1Iterator.executeQuery();
                                        if (Utils.fileUpload(blob.getInputStream(),
                                                             Utils.ENUM_CAU_HINH_KHOA.DLCT_DIR,
                                                             "HtCauHinhView1Iterator",
                                                             htFileRow)) {
                                            rows[i].setAttribute("HtFileId",
                                                                 ((DBSequence)htFileRow.getAttribute("Id")).getSequenceNumber());
                                            rows[i].setAttribute("ValNumber",
                                                                 null);
                                            rows[i].setAttribute("ValVarchar",
                                                                 null);
                                            rows[i].setAttribute("ValBlob",
                                                                 null);
                                        } else {
                                            String errorString =
                                                Utils.getResourceBundle("LOI_TRONG_QUA_TRINH_LUU_FILE");
                                            FacesContext.getCurrentInstance().addMessage(dialogEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                                         new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                          errorString,
                                                                                                          errorString));
                                            createPhysicFile = false;
                                        }
                                    }
                                } else {
                                    rows[i].setAttribute("ValNumber", null);
                                    rows[i].setAttribute("ValVarchar", null);
                                    rows[i].setAttribute("ValBlob", null);
                                    rows[i].setAttribute("HtFileId", null);
                                    Row htFileRow =
                                        (Row)rows[i].getAttribute("HtFileView");
                                    if (htFileRow != null) {
                                        String duongDan =
                                            (String)htFileRow.getAttribute("DuongDan");
                                        listFileDelete.add(new File(rootFile,
                                                                    duongDan));
                                        fileView1Iterator.removeRowWithKey(htFileRow.getKey().toStringFormat(false));
                                    }
                                }
                            }
                            if (kieuDuLieu.intValue() ==
                                Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
                                Number trangThai =
                                    (Number)rows[i].getAttribute("ValNumber");
                                String tenFile =
                                    (String)rows[i].getAttribute("ValVarchar");
                                BlobDomain blob =
                                    (BlobDomain)rows[i].getAttribute("ValBlob");
                                if (trangThai == null ||
                                    trangThai.intValue() ==
                                    Utils.ENUM_TRANG_THAI.CONG_BO.getId()) {
                                    if (tenFile != null && blob != null) {
                                        Row htFileRow =
                                            (Row)rows[i].getAttribute("HtFileView");
                                        if (htFileRow != null) {
                                            String duongDan =
                                                (String)htFileRow.getAttribute("DuongDan");
                                            listFileDelete.add(new File(rootFile,
                                                                        duongDan));
                                            fileView1Iterator.removeRowWithKey(htFileRow.getKey().toStringFormat(false));
                                        }
                                        NameValuePairs nvp =
                                            new NameValuePairs();
                                        nvp.setAttribute("TenFile", tenFile);
                                        nvp.setAttribute("MaUngDung",
                                                         Utils.ENUM_MA_UNG_DUNG.DLCT.getMaUngDung());
                                        htFileRow =
                                                fileView1Iterator.getViewObject().createAndInitRow(nvp);
                                        fileView1Iterator.executeQuery();
                                        if (Utils.fileUpload(blob.getInputStream(),
                                                             Utils.ENUM_CAU_HINH_KHOA.DLCT_DIR,
                                                             "HtCauHinhView1Iterator",
                                                             htFileRow)) {
                                            rows[i].setAttribute("HtFileId",
                                                                 ((DBSequence)htFileRow.getAttribute("Id")).getSequenceNumber());
                                            rows[i].setAttribute("ValNumber",
                                                                 null);
                                            rows[i].setAttribute("ValVarchar",
                                                                 null);
                                            rows[i].setAttribute("ValBlob",
                                                                 null);
                                        } else {
                                            String errorString =
                                                Utils.getResourceBundle("LOI_TRONG_QUA_TRINH_LUU_FILE");
                                            FacesContext.getCurrentInstance().addMessage(dialogEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                                                         new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                          errorString,
                                                                                                          errorString));
                                            createPhysicFile = false;
                                        }
                                    }
                                } else {
                                    rows[i].setAttribute("ValNumber", null);
                                    rows[i].setAttribute("ValVarchar", null);
                                    rows[i].setAttribute("ValBlob", null);
                                    rows[i].setAttribute("HtFileId", null);
                                    Row htFileRow =
                                        (Row)rows[i].getAttribute("HtFileView");
                                    if (htFileRow != null) {
                                        String duongDan =
                                            (String)htFileRow.getAttribute("DuongDan");
                                        listFileDelete.add(new File(rootFile,
                                                                    duongDan));
                                        fileView1Iterator.removeRowWithKey(htFileRow.getKey().toStringFormat(false));
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                String errorString =
                    Utils.getResourceBundle("LOI_TRONG_QUA_TRINH_LUU_FILE");
                FacesContext.getCurrentInstance().addMessage(dialogEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                              errorString,
                                                                              errorString));
                createPhysicFile = false;
            }
            if (createPhysicFile) {
                for (File file : listFileDelete) {
                    file.delete();
                }
                for (String key : listDelete) {
                    gtDvTtView1Iterator.removeRowWithKey(key);
                }
                listDelete = new ArrayList();
                dvLdvView1Iterator.setRangeSize(-1);
                rows = dvLdvView1Iterator.getAllRowsInRange();
                if (rows == null) {
                    rows = new Row[] { };
                }
                for (int i = 0; i < rows.length; i++) {
                    listDelete.add(rows[i].getKey().toStringFormat(false));
                }
                for (String key : listDelete) {
                    dvLdvView1Iterator.removeRowWithKey(key);
                }
                listDelete = new ArrayList();
                dvNnView1Iterator.setRangeSize(-1);
                rows = dvNnView1Iterator.getAllRowsInRange();
                if (rows == null) {
                    rows = new Row[] { };
                }
                for (int i = 0; i < rows.length; i++) {
                    listDelete.add(rows[i].getKey().toStringFormat(false));
                }
                for (String key : listDelete) {
                    dvNnView1Iterator.removeRowWithKey(key);
                }


                List<String> listLoaiDonViId =
                    (List<String>)selectLoaiDonVi.getValue();
                List<String> listNgonNguId =
                    (List<String>)selectNgonNgu.getValue();
                for (String loaiDonViId : listLoaiDonViId) {
                    Number idNumber = null;
                    try {
                        idNumber = new Number(loaiDonViId);
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    if (idNumber != null) {
                        NameValuePairs nvp = new NameValuePairs();
                        nvp.setAttribute("DlctLoaiDonViId", idNumber);
                        nvp.setAttribute("MaUngDung",
                                         Utils.ENUM_MA_UNG_DUNG.DLCT.getMaUngDung());
                        dvLdvView1Iterator.getViewObject().createAndInitRow(nvp);
                        dvLdvView1Iterator.executeQuery();
                    }
                }
                for (String ngonNguId : listNgonNguId) {
                    Number idNumber = null;
                    try {
                        idNumber = new Number(ngonNguId);
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    if (idNumber != null) {
                        NameValuePairs nvp = new NameValuePairs();
                        nvp.setAttribute("DlctNgonNgu", idNumber);
                        nvp.setAttribute("MaUngDung",
                                         Utils.ENUM_MA_UNG_DUNG.DLCT.getMaUngDung());
                        dvNnView1Iterator.getViewObject().createAndInitRow(nvp);
                        dvLdvView1Iterator.executeQuery();
                    }
                }
                DCIteratorBinding donViView1Iterator =
                    Utils.getIteratorBinding("DlctDonViView1Iterator");
                donViView1Iterator.getDataControl().getApplicationModule().getTransaction().commit();
                String rowKey =
                    donViView1Iterator.getCurrentRow().getKey().toStringFormat(false);
                iteratorFilter();
                donViView1Iterator.setRangeSize(-1);
                donViView1Iterator.setCurrentRowWithKey(rowKey);
                int pageSize = Utils.getPageSize("HtCauHinhView1Iterator");
                int rowIndex = donViView1Iterator.getCurrentRowIndexInRange();
                int pageNum = 0;
                if (rowIndex % pageSize == 0) {
                    pageNum = rowIndex / pageSize + 1;
                } else {
                    pageNum = rowIndex / pageSize + 1;
                }
                getValue(pageNum);
            }
        }
    }

    public void delete(DialogEvent dialogEvent) {
        try {
            Map<String, Object> mapSelectedRow =
                (Map<String, Object>)tableDonVi.getSelectedRowData();
            if (mapSelectedRow != null) {
                DCIteratorBinding donViView1Iterator =
                    Utils.getIteratorBinding("DlctDonViView1Iterator");
                donViView1Iterator.setCurrentRowWithKey((String)mapSelectedRow.get(ROW_KEY));
                DCIteratorBinding dvLdvView1Iterator =
                    Utils.getIteratorBinding("DlctDvLdvView1Iterator");
                DCIteratorBinding dvNnView1Iterator =
                    Utils.getIteratorBinding("DlctDvNnView1Iterator");
                DCIteratorBinding gtDvTtView1Iterator =
                    Utils.getIteratorBinding("DlctGtDvTtView1Iterator");
                List<String> listDelete = new ArrayList();
                gtDvTtView1Iterator.setRangeSize(-1);
                Row[] rows = gtDvTtView1Iterator.getAllRowsInRange();
                if (rows == null) {
                    rows = new Row[] { };
                }
                for (int i = 0; i < rows.length; i++) {
                    listDelete.add(rows[i].getKey().toStringFormat(false));
                }
                for (String key : listDelete) {
                    gtDvTtView1Iterator.removeRowWithKey(key);
                }
                listDelete = new ArrayList();
                dvLdvView1Iterator.setRangeSize(-1);
                rows = dvLdvView1Iterator.getAllRowsInRange();
                if (rows == null) {
                    rows = new Row[] { };
                }
                for (int i = 0; i < rows.length; i++) {
                    listDelete.add(rows[i].getKey().toStringFormat(false));
                }
                for (String key : listDelete) {
                    dvLdvView1Iterator.removeRowWithKey(key);
                }
                listDelete = new ArrayList();
                dvNnView1Iterator.setRangeSize(-1);
                rows = dvNnView1Iterator.getAllRowsInRange();
                if (rows == null) {
                    rows = new Row[] { };
                }
                for (int i = 0; i < rows.length; i++) {
                    listDelete.add(rows[i].getKey().toStringFormat(false));
                }
                for (String key : listDelete) {
                    dvNnView1Iterator.removeRowWithKey(key);
                }
                donViView1Iterator.removeCurrentRow();
                donViView1Iterator.getDataControl().getApplicationModule().getTransaction().commit();
            }
            iteratorFilter();
            Integer pageNum = null;
            try {
                pageNum = new Integer(goToPage.getValue().toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (pageNum != null) {
                getValue(pageNum.intValue());
            }
        } catch (Exception e) {
            String errorString =
                Utils.getResourceBundle("CON_BAN_GHI_LIEN_QUAN");
            FacesContext.getCurrentInstance().addMessage(dialogEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                         new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                          errorString,
                                                                          errorString));
            e.printStackTrace();
        }
    }

    private List<UIComponent> createSearchComponent(String id, String ten,
                                                    int kieu) {
        List<UIComponent> result = new ArrayList();
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
            DateTimeConverter converter =
                (DateTimeConverter)FacesContext.getCurrentInstance().getApplication().createConverter("javax.faces.DateTime");
            converter.setLocale(new Locale(DEFAULT_LANGCODE));
            converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
            converter.setType("date");
            converter.setDateStyle("short");
            RichInputDate inputDate = new RichInputDate();
            inputDate.setConverter(converter);
            inputDate.setId(id);
            inputDate.setLabel(ten);
            inputDate.setAutoSubmit(true);
            result.add(inputDate);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId()) {
            UISelectItems uiSelectItems = new UISelectItems();
            uiSelectItems.setValue(listSelectItemLoaiChungKhoan(null));
            RichSelectOneChoice selectOneChoice = new RichSelectOneChoice();
            selectOneChoice.setId(id);
            selectOneChoice.setLabel(ten);
            selectOneChoice.getChildren().clear();
            selectOneChoice.getChildren().add(uiSelectItems);
            selectOneChoice.setValuePassThru(true);
            selectOneChoice.setAutoSubmit(true);
            result.add(selectOneChoice);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
            UISelectItems uiSelectItems = new UISelectItems();
            uiSelectItems.setValue(listSelectItemSanGiaoDich(null));
            RichSelectOneChoice selectOneChoice = new RichSelectOneChoice();
            selectOneChoice.setId(id);
            selectOneChoice.setLabel(ten);
            selectOneChoice.getChildren().clear();
            selectOneChoice.getChildren().add(uiSelectItems);
            selectOneChoice.setValuePassThru(true);
            selectOneChoice.setAutoSubmit(true);
            result.add(selectOneChoice);
        }
        return result;
    }

    private List<UIComponent> createInputComponent(String id, String ten,
                                                   Number ngonNguId, int kieu,
                                                   int batBuoc, Object value,
                                                   boolean disable) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        MethodExpression methodExpression =
            elFactory.createMethodExpression(elContext,
                                             "#{dmDonViBean.changeUpdateField}",
                                             null,
                                             new Class[] { ValueChangeEvent.class });
        List<UIComponent> result = new ArrayList();
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setDisabled(disable);
            inputText.setAutoSubmit(true);
            inputText.setRequired(batBuoc ==
                                  Utils.ENUM_BAT_BUOC.BAT_BUOC.getId());
            inputText.setRequiredMessageDetail(Utils.getResourceBundle("TRUONG_DU_LIEU_BAT_BUOC"));
            inputText.setValue(value);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            inputText.getAttributes().put("valueChangeListener",
                                          methodExpressionMethodBinding);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setDisabled(disable);
            inputText.setAutoSubmit(true);
            inputText.setRequired(batBuoc ==
                                  Utils.ENUM_BAT_BUOC.BAT_BUOC.getId());
            inputText.setRequiredMessageDetail(Utils.getResourceBundle("TRUONG_DU_LIEU_BAT_BUOC"));
            inputText.setValue(value);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            inputText.getAttributes().put("valueChangeListener",
                                          methodExpressionMethodBinding);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setDisabled(disable);
            inputText.setAutoSubmit(true);
            inputText.setRequired(batBuoc ==
                                  Utils.ENUM_BAT_BUOC.BAT_BUOC.getId());
            inputText.setRequiredMessageDetail(Utils.getResourceBundle("TRUONG_DU_LIEU_BAT_BUOC"));
            inputText.setValue(value);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            inputText.getAttributes().put("valueChangeListener",
                                          methodExpressionMethodBinding);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setDisabled(disable);
            inputText.setAutoSubmit(true);
            inputText.setRequired(batBuoc ==
                                  Utils.ENUM_BAT_BUOC.BAT_BUOC.getId());
            inputText.setRequiredMessageDetail(Utils.getResourceBundle("TRUONG_DU_LIEU_BAT_BUOC"));
            inputText.setValue(value);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            inputText.getAttributes().put("valueChangeListener",
                                          methodExpressionMethodBinding);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
            DateTimeConverter converter =
                (DateTimeConverter)FacesContext.getCurrentInstance().getApplication().createConverter("javax.faces.DateTime");
            converter.setLocale(new Locale(DEFAULT_LANGCODE));
            converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
            converter.setType("date");
            converter.setDateStyle("short");
            RichInputDate inputDate = new RichInputDate();
            inputDate.setConverter(converter);
            inputDate.setId(id);
            inputDate.setLabel(ten);
            inputDate.setDisabled(disable);
            inputDate.setAutoSubmit(true);
            inputDate.setRequired(batBuoc ==
                                  Utils.ENUM_BAT_BUOC.BAT_BUOC.getId());
            inputDate.setRequiredMessageDetail(Utils.getResourceBundle("TRUONG_DU_LIEU_BAT_BUOC"));
            inputDate.setValue(value);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            inputDate.getAttributes().put("valueChangeListener",
                                          methodExpressionMethodBinding);
            result.add(inputDate);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
            RichTextEditor textEditor = new RichTextEditor();
            textEditor.setId(id);
            textEditor.setLabel(ten);
            textEditor.setDisabled(disable);
            textEditor.setAutoSubmit(true);
            textEditor.setRequired(batBuoc ==
                                   Utils.ENUM_BAT_BUOC.BAT_BUOC.getId());
            textEditor.setRequiredMessageDetail(Utils.getResourceBundle("TRUONG_DU_LIEU_BAT_BUOC"));
            textEditor.setValue(value);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            textEditor.getAttributes().put("valueChangeListener",
                                           methodExpressionMethodBinding);
            result.add(textEditor);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
            RichInputFile inputFile = new RichInputFile();
            inputFile.setId(id);
            inputFile.setLabel(ten);
            inputFile.setDisabled(disable);
            inputFile.setAutoSubmit(true);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            inputFile.getAttributes().put("valueChangeListener",
                                          methodExpressionMethodBinding);
            result.add(inputFile);
            RichPanelGroupLayout groupLayout = new RichPanelGroupLayout();
            groupLayout.setLayout(groupLayout.LAYOUT_HORIZONTAL);
            groupLayout.setId(id + FILE_GROUP_ID_SUBFIX);

            methodExpression =
                    elFactory.createMethodExpression(elContext, "#{dmDonViBean.fileDownload}",
                                                     null,
                                                     new Class[] { ActionEvent.class });
            methodExpressionMethodBinding =
                    new MethodExpressionMethodBinding(methodExpression);
            RichCommandLink buttonDownload = new RichCommandLink();
            buttonDownload.setImmediate(true);
            buttonDownload.setPartialSubmit(true);
            buttonDownload.setId(id + FILE_DOWNLOAD_ID_SUBFIX);
            buttonDownload.setText((String)value);
            buttonDownload.getAttributes().put("actionListener",
                                               methodExpressionMethodBinding);
            groupLayout.getChildren().add(buttonDownload);

            if (disable == false) {
                ValueExpression valueExp =
                    elFactory.createValueExpression(elContext,
                                                    "#{adfBundle['view.ViewControllerBundle'].XOA}",
                                                    Object.class);
                methodExpression =
                        elFactory.createMethodExpression(elContext, "#{dmDonViBean.removeFile}",
                                                         null,
                                                         new Class[] { ActionEvent.class });
                methodExpressionMethodBinding =
                        new MethodExpressionMethodBinding(methodExpression);
                RichCommandToolbarButton buttonRemove =
                    new RichCommandToolbarButton();
                buttonRemove.setImmediate(true);
                buttonRemove.setPartialSubmit(true);
                buttonRemove.setId(id + FILE_REMOVE_ID_SUBFIX);
                buttonRemove.setValueExpression("text", valueExp);
                buttonRemove.getAttributes().put("actionListener",
                                                 methodExpressionMethodBinding);
                groupLayout.getChildren().add(buttonRemove);
            }
            if (value != null) {
                groupLayout.setVisible(true);
            } else {
                groupLayout.setVisible(false);
            }
            result.add(groupLayout);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LOGO.getId()) {
            RichInputFile inputFile = new RichInputFile();
            inputFile.setId(id);
            inputFile.setLabel(ten);
            inputFile.setDisabled(disable);
            inputFile.setAutoSubmit(true);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            inputFile.getAttributes().put("valueChangeListener",
                                          methodExpressionMethodBinding);
            result.add(inputFile);
            RichPanelGroupLayout groupLayout = new RichPanelGroupLayout();
            groupLayout.setLayout(groupLayout.LAYOUT_HORIZONTAL);
            groupLayout.setId(id + FILE_GROUP_ID_SUBFIX);

            methodExpression =
                    elFactory.createMethodExpression(elContext, "#{dmDonViBean.fileDownload}",
                                                     null,
                                                     new Class[] { ActionEvent.class });
            methodExpressionMethodBinding =
                    new MethodExpressionMethodBinding(methodExpression);
            RichCommandLink buttonDownload = new RichCommandLink();
            buttonDownload.setImmediate(true);
            buttonDownload.setPartialSubmit(true);
            buttonDownload.setId(id + FILE_DOWNLOAD_ID_SUBFIX);
            buttonDownload.setText((String)value);
            buttonDownload.getAttributes().put("actionListener",
                                               methodExpressionMethodBinding);
            groupLayout.getChildren().add(buttonDownload);

            if (disable == false) {
                ValueExpression valueExp =
                    elFactory.createValueExpression(elContext,
                                                    "#{adfBundle['view.ViewControllerBundle'].XOA}",
                                                    Object.class);
                methodExpression =
                        elFactory.createMethodExpression(elContext, "#{dmDonViBean.removeFile}",
                                                         null,
                                                         new Class[] { ActionEvent.class });
                methodExpressionMethodBinding =
                        new MethodExpressionMethodBinding(methodExpression);
                RichCommandToolbarButton buttonRemove =
                    new RichCommandToolbarButton();
                buttonRemove.setImmediate(true);
                buttonRemove.setPartialSubmit(true);
                buttonRemove.setId(id + FILE_REMOVE_ID_SUBFIX);
                buttonRemove.setValueExpression("text", valueExp);
                buttonRemove.getAttributes().put("actionListener",
                                                 methodExpressionMethodBinding);
                groupLayout.getChildren().add(buttonRemove);
            }
            if (value != null) {
                groupLayout.setVisible(true);
            } else {
                groupLayout.setVisible(false);
            }
            result.add(groupLayout);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LOAI_CHUNG_KHOAN.getId()) {
            UISelectItems uiSelectItems = new UISelectItems();
            uiSelectItems.setValue(listSelectItemLoaiChungKhoan(ngonNguId));
            RichSelectOneChoice selectOneChoice = new RichSelectOneChoice();
            selectOneChoice.setId(id);
            selectOneChoice.setLabel(ten);
            selectOneChoice.setDisabled(disable);
            selectOneChoice.getChildren().clear();
            selectOneChoice.getChildren().add(uiSelectItems);
            selectOneChoice.setValuePassThru(true);
            selectOneChoice.setAutoSubmit(true);
            selectOneChoice.setRequired(batBuoc ==
                                        Utils.ENUM_BAT_BUOC.BAT_BUOC.getId());
            selectOneChoice.setRequiredMessageDetail(Utils.getResourceBundle("TRUONG_DU_LIEU_BAT_BUOC"));
            selectOneChoice.setValue(value);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            selectOneChoice.getAttributes().put("valueChangeListener",
                                                methodExpressionMethodBinding);
            result.add(selectOneChoice);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.SAN_GIAO_DICH.getId()) {
            UISelectItems uiSelectItems = new UISelectItems();
            uiSelectItems.setValue(listSelectItemSanGiaoDich(ngonNguId));
            RichSelectOneChoice selectOneChoice = new RichSelectOneChoice();
            selectOneChoice.setId(id);
            selectOneChoice.setLabel(ten);
            selectOneChoice.setDisabled(disable);
            selectOneChoice.getChildren().clear();
            selectOneChoice.getChildren().add(uiSelectItems);
            selectOneChoice.setValuePassThru(true);
            selectOneChoice.setAutoSubmit(true);
            selectOneChoice.setRequired(batBuoc ==
                                        Utils.ENUM_BAT_BUOC.BAT_BUOC.getId());
            selectOneChoice.setRequiredMessageDetail(Utils.getResourceBundle("TRUONG_DU_LIEU_BAT_BUOC"));
            selectOneChoice.setValue(value);
            selectOneChoice.setUnselectedLabel("--Chọn--");
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            selectOneChoice.getAttributes().put("valueChangeListener",
                                                methodExpressionMethodBinding);
            result.add(selectOneChoice);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.IN_OUT_KIEM_TOAN_VIEN.getId() ||
            kieu == Utils.ENUM_KIEU_DU_LIEU.KIEM_TOAN_VIEN.getId() ||
            kieu == Utils.ENUM_KIEU_DU_LIEU.SL_KIEM_TOAN_VIEN.getId()) {
            ten =
ten.replace("{0}", "" + Calendar.getInstance().get(Calendar.YEAR));
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setRequired(false);
            inputText.setDisabled(true);
            result.add(inputText);
        }
        return result;
    }

    private List<SelectItem> listSelectItemLoaiChungKhoan(Number ngonNguId) {
        List<AdvancedSearchGroup> listASG = new ArrayList();
        AdvancedSearchGroup asg = new AdvancedSearchGroup();
        listASG.add(asg);
        AdvancedSearchItem asi = new AdvancedSearchItem();
        asg.getListChildren().add(asi);
        asi.setItemName("TrangThai");
        asi.setRequired(true);
        asi.getListValue().add(0,
                               new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        if (ngonNguId != null) {
            asi = new AdvancedSearchItem();
            asi.setItemName("DlctLckNnView");
            asi.setRequired(true);
            asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
            AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
            asi.getListChildren().add(asgChild);
            AdvancedSearchItem asiChild = new AdvancedSearchItem();
            asgChild.getListChildren().add(asiChild);
            asiChild.setItemName("DlctLoaiDonViId");
            asiChild.setRequired(true);
            asiChild.getListValue().add(ngonNguId);
        }
        Utils.searchadvanced("DlctLoaiChungKhoanView1Iterator", listASG);
        DCIteratorBinding loaiChungKhoanView1Iterator =
            Utils.getIteratorBinding("DlctLoaiChungKhoanView1Iterator");
        List<SelectItem> listSelectItem = new ArrayList();
        loaiChungKhoanView1Iterator.setRangeSize(-1);
        Row[] rows = loaiChungKhoanView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        for (int i = 0; i < rows.length; i++) {
            String id = ((DBSequence)rows[i].getAttribute("Id")).toString();
            String ten = "";

            RowSet gtLckTtRowSet =
                (RowSet)rows[i].getAttribute("DlctGtLckTtView");
            if (gtLckTtRowSet != null) {
                gtLckTtRowSet.setRangeSize(-1);
                Row[] gtLckTtRows = gtLckTtRowSet.getAllRowsInRange();
                if (gtLckTtRows == null) {
                    gtLckTtRows = new Row[] { };
                }
                for (int j = 0; j < gtLckTtRows.length; j++) {
                    Row truongTtRow =
                        (Row)gtLckTtRows[j].getAttribute("DlctTruongTtView");
                    Number kieuDuLieu =
                        (Number)truongTtRow.getAttribute("KieuDuLieu");
                    Number viTriHienThi =
                        (Number)truongTtRow.getAttribute("ViTriHienThi");
                    Number truongTtTu =
                        (Number)truongTtRow.getAttribute("DlctTruongTtTuId");
                    if (viTriHienThi != null && kieuDuLieu != null &&
                        truongTtTu == null) {
                        int viTri = viTriHienThi.intValue();
                        int kieu = kieuDuLieu.intValue();
                        if ((Utils.ENUM_VI_TRI_HIEN_THI.SELECT.getId() &
                             viTri) ==
                            Utils.ENUM_VI_TRI_HIEN_THI.SELECT.getId()) {
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                Number valNumber =
                                    (Number)gtLckTtRows[j].getAttribute("ValNumber");
                                if (valNumber != null) {
                                    ten = ten + valNumber.toString() + " ";
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                String valVarchar =
                                    (String)gtLckTtRows[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    ten = ten + valVarchar + " ";
                                }
                            }
                        }
                    }
                }
            }

            SelectItem si = new SelectItem();
            si.setValue(id);
            si.setLabel(ten);
            listSelectItem.add(si);
        }
        return listSelectItem;
    }

    private List<SelectItem> listSelectItemSanGiaoDich(Number ngonNguId) {
        List<AdvancedSearchGroup> listASG = new ArrayList();
        AdvancedSearchGroup asg = new AdvancedSearchGroup();
        listASG.add(asg);
        AdvancedSearchItem asi = new AdvancedSearchItem();
        asg.getListChildren().add(asi);
        asi.setItemName("TrangThai");
        asi.setRequired(true);
        asi.getListValue().add(0,
                               new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        if (ngonNguId != null) {
            asi = new AdvancedSearchItem();
            asi.setItemName("DlctLckNnView");
            asi.setRequired(true);
            asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
            AdvancedSearchGroup asgChild = new AdvancedSearchGroup();
            asi.getListChildren().add(asgChild);
            AdvancedSearchItem asiChild = new AdvancedSearchItem();
            asgChild.getListChildren().add(asiChild);
            asiChild.setItemName("DlctLoaiDonViId");
            asiChild.setRequired(true);
            asiChild.getListValue().add(ngonNguId);
        }
        Utils.searchadvanced("DlctSanGiaoDichView1Iterator", listASG);
        DCIteratorBinding sanGiaoDichView1Iterator =
            Utils.getIteratorBinding("DlctSanGiaoDichView1Iterator");
        List<SelectItem> listSelectItem = new ArrayList();
        sanGiaoDichView1Iterator.setRangeSize(-1);
        Row[] rows = sanGiaoDichView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        for (int i = 0; i < rows.length; i++) {
            String id = ((DBSequence)rows[i].getAttribute("Id")).toString();
            String ten = "";
            RowSet gtLckTtRowSet =
                (RowSet)rows[i].getAttribute("DlctGtSgdTtView");
            if (gtLckTtRowSet != null) {
                gtLckTtRowSet.setRangeSize(-1);
                Row[] gtLckTtRows = gtLckTtRowSet.getAllRowsInRange();
                if (gtLckTtRows == null) {
                    gtLckTtRows = new Row[] { };
                }
                for (int j = 0; j < gtLckTtRows.length; j++) {
                    Row truongTtRow =
                        (Row)gtLckTtRows[j].getAttribute("DlctTruongTtView");
                    Number kieuDuLieu =
                        (Number)truongTtRow.getAttribute("KieuDuLieu");
                    Number viTriHienThi =
                        (Number)truongTtRow.getAttribute("ViTriHienThi");
                    Number truongTtTu =
                        (Number)truongTtRow.getAttribute("DlctTruongTtTuId");
                    if (viTriHienThi != null && kieuDuLieu != null &&
                        truongTtTu == null) {
                        int viTri = viTriHienThi.intValue();
                        int kieu = kieuDuLieu.intValue();
                        if ((Utils.ENUM_VI_TRI_HIEN_THI.SELECT.getId() &
                             viTri) ==
                            Utils.ENUM_VI_TRI_HIEN_THI.SELECT.getId()) {
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                Number valNumber =
                                    (Number)gtLckTtRows[j].getAttribute("ValNumber");
                                if (valNumber != null) {
                                    ten = ten + valNumber.toString() + " ";
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                String valVarchar =
                                    (String)gtLckTtRows[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    ten = ten + valVarchar + " ";
                                }
                            }
                        }
                    }
                }
            }
            SelectItem si = new SelectItem();
            si.setValue(id);
            si.setLabel(ten);
            listSelectItem.add(si);
        }
        return listSelectItem;
    }

    private UIComponent createColumn(String id, String ten, int kieu) {
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.IN_OUT_KIEM_TOAN_VIEN.getId() ||
            kieu == Utils.ENUM_KIEU_DU_LIEU.KIEM_TOAN_VIEN.getId() ||
            kieu == Utils.ENUM_KIEU_DU_LIEU.SL_KIEM_TOAN_VIEN.getId()) {
            return null;
        } else {
            FacesContext fc = FacesContext.getCurrentInstance();
            Application app = fc.getApplication();
            ExpressionFactory elFactory = app.getExpressionFactory();
            ELContext elContext = fc.getELContext();
            ValueExpression valueExp;
            RichColumn column = new RichColumn();
            column.setHeaderText(ten);
            RichOutputText outputText = new RichOutputText();
            valueExp =
                    elFactory.createValueExpression(elContext, "#{row['" + id +
                                                    "']}", Object.class);
            outputText.setValueExpression("value", valueExp);
            if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                DateTimeConverter converter =
                    (DateTimeConverter)FacesContext.getCurrentInstance().getApplication().createConverter("javax.faces.DateTime");
                converter.setLocale(new Locale(DEFAULT_LANGCODE));
                converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
                converter.setType("date");
                converter.setDateStyle("short");
                outputText.setConverter(converter);
            }
            if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                outputText.setEscape(true);
            }
            column.getChildren().add(outputText);
            return column;
        }
    }

    public void setSearchPanel(RichPanelFormLayout searchPanel) {
        this.searchPanel = searchPanel;
    }

    public RichPanelFormLayout getSearchPanel() {
        return searchPanel;
    }

    public void setTableDonVi(RichTable tableDonVi) {
        this.tableDonVi = tableDonVi;
    }

    public RichTable getTableDonVi() {
        return tableDonVi;
    }

    public void setGoToPage(RichSelectOneChoice goToPage) {
        this.goToPage = goToPage;
    }

    public RichSelectOneChoice getGoToPage() {
        return goToPage;
    }

    public void setPopupUpdate(RichPopup popupUpdate) {
        this.popupUpdate = popupUpdate;
    }

    public RichPopup getPopupUpdate() {
        return popupUpdate;
    }

    public void setDialogUpdate(RichDialog dialogUpdate) {
        this.dialogUpdate = dialogUpdate;
    }

    public RichDialog getDialogUpdate() {
        return dialogUpdate;
    }

    public void setPopupDelete(RichPopup popupDelete) {
        this.popupDelete = popupDelete;
    }

    public RichPopup getPopupDelete() {
        return popupDelete;
    }

    public void setSelectLoaiDonVi(RichSelectOrderShuttle selectLoaiDonVi) {
        this.selectLoaiDonVi = selectLoaiDonVi;
    }

    public RichSelectOrderShuttle getSelectLoaiDonVi() {
        return selectLoaiDonVi;
    }

    public void setSelectNgonNgu(RichSelectOrderShuttle selectNgonNgu) {
        this.selectNgonNgu = selectNgonNgu;
    }

    public RichSelectOrderShuttle getSelectNgonNgu() {
        return selectNgonNgu;
    }

    public void setUpdatePanel(RichPanelTabbed updatePanel) {
        this.updatePanel = updatePanel;
    }

    public RichPanelTabbed getUpdatePanel() {
        return updatePanel;
    }

    public void setFirstPage(RichCommandToolbarButton firstPage) {
        this.firstPage = firstPage;
    }

    public RichCommandToolbarButton getFirstPage() {
        return firstPage;
    }

    public void setPrevPage(RichCommandToolbarButton prevPage) {
        this.prevPage = prevPage;
    }

    public RichCommandToolbarButton getPrevPage() {
        return prevPage;
    }

    public void setNextPage(RichCommandToolbarButton nextPage) {
        this.nextPage = nextPage;
    }

    public RichCommandToolbarButton getNextPage() {
        return nextPage;
    }

    public void setLastPage(RichCommandToolbarButton lastPage) {
        this.lastPage = lastPage;
    }

    public RichCommandToolbarButton getLastPage() {
        return lastPage;
    }

    public void setFileDownloadButton(RichCommandButton fileDownloadButton) {
        this.fileDownloadButton = fileDownloadButton;
    }

    public RichCommandButton getFileDownloadButton() {
        return fileDownloadButton;
    }
}
